cli/connhelper/commandcon.New: pass context with WithoutCancel#5816
Merged
vvoland merged 1 commit intodocker:masterfrom Feb 11, 2025
Merged
cli/connhelper/commandcon.New: pass context with WithoutCancel#5816vvoland merged 1 commit intodocker:masterfrom
vvoland merged 1 commit intodocker:masterfrom
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 <github@gone.nl>
thaJeztah
commented
Feb 10, 2025
Comment on lines
+36
to
+50
| 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...)} |
Member
Author
There was a problem hiding this comment.
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 |
vvoland
approved these changes
Feb 11, 2025
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.
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)