-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cli/connhelper/commandcon.New: pass context with WithoutCancel #5816
Conversation
Passing the context to the constructor, but explicitly making it non-cancelable and add a comment describing why context-cancelation should not be propagated. Signed-off-by: Sebastiaan van Stijn <[email protected]>
func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) { | ||
// Don't kill the ssh process if the context is cancelled. Killing the | ||
// ssh process causes an error when go's http.Client tries to reuse the | ||
// net.Conn (commandConn). | ||
// | ||
// Not passing down the Context might seem counter-intuitive, but in this | ||
// case, the lifetime of the process should be managed by the http.Client, | ||
// not the caller's Context. | ||
// | ||
// Further details;; | ||
// | ||
// - https://github.com/docker/cli/pull/3900 | ||
// - https://github.com/docker/compose/issues/9448#issuecomment-1264263721 | ||
ctx = context.WithoutCancel(ctx) | ||
c := commandConn{cmd: exec.CommandContext(ctx, cmd, args...)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was THIS close to passing the context, when I recalled there was some change related to this code to not pass it.
So instead, I passed through the context (which could be used to pass a context logger), and added a WithoutCancel
... and a large comment explaining why to prevent future others (or future self) from reintroducing the issue that was fixed (which may be even more relevant if this code is moved to a separate module)
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5816 +/- ##
==========================================
+ Coverage 59.29% 59.30% +0.01%
==========================================
Files 353 353
Lines 29540 29550 +10
==========================================
+ Hits 17516 17526 +10
Misses 11043 11043
Partials 981 981 |
Passing the context to the constructor, but explicitly making it non-cancelable and add a comment describing why context-cancelation should not be propagated.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)