Fix memory leak in replication loop
Replication loop contains `defer` inside endless loop, leading to leak WithCancel context every loop turn.
@@ -102,6 +102,7 @@ func (r *replicator) start(stop <-chan struct{}) {
}
// Create a log reader starting at the requested offset.
+ func() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -116,7 +117,7 @@ func (r *replicator) start(stop <-chan struct{}) {
r.partition.srv.logger.Errorf("Failed to send HW for partition %s to replica %s: %v",
r.partition, req.ReplicaID, err)
}
- continue
+ return
}
// Send a batch of messages to the replica.
@@ -126,8 +127,9 @@ func (r *replicator) start(stop <-chan struct{}) {
r.partition.srv.logger.Errorf("Failed to send HW for partition %s to replica %s: %v",
r.partition, req.ReplicaID, err)
}
- continue
+ return
}
+ }()
}
}
