Skip to content
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

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

thaJeztah
Copy link
Member

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)

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]>
@thaJeztah thaJeztah added status/2-code-review kind/refactor PR's that refactor, or clean-up code labels 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...)}
Copy link
Member Author

@thaJeztah thaJeztah Feb 10, 2025

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-commenter
Copy link

codecov-commenter commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 59.30%. Comparing base (e6ee7ea) to head (2c17edf).
Report is 2 commits behind head on master.

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              

@thaJeztah thaJeztah self-assigned this Feb 10, 2025
@vvoland vvoland added this to the 28.0.0 milestone Feb 11, 2025
@vvoland vvoland merged commit 0af65dc into docker:master Feb 11, 2025
98 checks passed
@thaJeztah thaJeztah deleted the connhelper_context branch February 11, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/refactor PR's that refactor, or clean-up code status/2-code-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants