Fix snapshot transfer context leak causing BoltDB read transaction starvation #21188
+335
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix snapshot transfer context leak causing BoltDB read transaction starvation
Description
This PR fixes a critical resource leak in the
Maintenance.SnapshotgRPC API where a client disconnect during snapshot transfer could leave a snapshot writer goroutine running indefinitely.When a snapshot stream is canceled (e.g. client timeout, network drop, TCP RST), the server-side goroutine writing snapshot data to an
io.Pipecontinues running and blocks forever. This prevents the underlying BoltDB read transaction from being closed, leading to:The fix ensures snapshot generation respects gRPC context cancellation and always releases backend resources.
Type of change
The Problem
The snapshot writer goroutine does not observe
srv.Context().Done().If the client disconnects while
snap.WriteTo(pw)is running:WriteTo()blocks foreversnap.Close()is never calledThis is a silent failure that slowly degrades the cluster until writes fail.
Root Cause
io.PipeThe Fix
srv.Context().Done()during snapshot streamingWriteToThis guarantees snapshot resources are released in all exit paths.
Reproduction Steps
##Test