fix: prevent goroutine leak in terminal exec timeout handling#139
Closed
haosenwang1018 wants to merge 1 commit intovxcontrol:masterfrom
Closed
fix: prevent goroutine leak in terminal exec timeout handling#139haosenwang1018 wants to merge 1 commit intovxcontrol:masterfrom
haosenwang1018 wants to merge 1 commit intovxcontrol:masterfrom
Conversation
When getExecResult times out, the goroutine running io.Copy remains blocked on resp.Reader indefinitely because resp is only closed via defer after the function returns. This leaks one goroutine per timed-out command. Fix: close resp.Conn explicitly on timeout to unblock io.Copy, then wait for the goroutine to finish before returning. On the normal (non-timeout) path, close resp immediately after the copy completes. Fixes vxcontrol#108
Contributor
|
hey @haosenwang1018 these changes was included by #124 into temporary branch it'll be added today in the master branch thank you for suggestion! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When
getExecResulttimes out viactx.Done(), the function returns but leaves a goroutine blocked onio.Copy(&dst, resp.Reader). The connection (resp) is only closed bydeferafter the function returns, but by that point the goroutine is already leaked —io.Copymay remain blocked even afterresp.Close()because the close races with the blocked read.Each timed-out command leaks one goroutine and its associated resources (#108).
Fix
respbefore waiting for the goroutine on timeout, which unblocksio.Copy<-done) after closing to ensure clean shutdownrespimmediately after copy completesdefer resp.Close()since both paths now close explicitlyBefore
After
Fixes #108