-
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
Don't print "context canceled" if user terminated #5778
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ import ( | |
|
||
func main() { | ||
err := dockerMain(context.Background()) | ||
if err != nil && !errdefs.IsCancelled(err) { | ||
if err != nil && !errdefs.IsCancelled(err) && !errors.Is(err, context.Canceled) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This improves clarity by reducing unnecessary negations. |
||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
os.Exit(getExitCode(err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess existing code didn't do so, but was wondering if the exit code (of explicitly set) should still be regarded (not sure) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so – in the past I think we've actually reviewed things to not exit with an erroneous exit code in some instances. We could take a look and see what other tools do though, and what makes sense. @tianon thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'm missing some nuance to the question 😅 ❤️ In general, I think the case described (Ctrl+C to cancel the pull during There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example: $ sleep 100
^C
$ echo $?
130 (but this feels too obvious, hence my thought that I must be missing some question nuance 😂) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nooo, you're definitely right. I was just wondering if there were some weird edge cases to this (if a user cancels mid confirmation prompt for example), or if you had some other thoughts. You're my goto for "I wonder if there's any weird expectations/precedent for [insert Unixy thing]".
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, in general a canceled operation should have a non-zero exit code, BUT with some exceptions, for example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Feels like it should fall under the general rule of non-zero exit code. My reasoning is, that if you execute (with terminal attached) a script like: set -x
docker login -u bork registry-1.docker.io
# do something after user logged in
docker pull ...
... Then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I definitely agree. Even for the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, that's also a fair point! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, yes, that also makes sense; I recall I was in doubt what would be correct when I wrote the ticket #5659;
So I wasn't sure what the correct way was to look at it;
But, obviously, that was from my perspective "I cancelled the pull", but it may not be limited to the user taking that action, and (for example) if the cancel happened as part of a script, then having a non-zero exit code would make a lot of sense (something happened, and the pull is not done!). And now I recall we made a similar mistake on |
||
} | ||
|
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.
Curious; errdefs.IsCancelled doesn't detect these? (that sounds like a possible bug if it doesn't)
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.
It doesn't, no. It checks that it implements the
errdefs
cancelled interface, not forcontext.Canceled
.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.
But don't we want to be specific to only ignoring the user cancelled the process vs something/someone cancelled the process? AFAIK
context.Canceled
can be a multitude of things and not just user cancelled.See #5760
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.
What else could cancel it though?
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.
Anything using
context.WithCancel()
can call thecancel
func inside its own logic and returnctx.Err()
. Since the error is ambiguous and can be used by anything down the call stack I'd prefer to impose a check on an error we know of. To me it seems it would be better to have something print outcontext canceled
in a case where we don't properly handle it than every occurrence ofcontext.Canceled
silencedThere 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'm okay with cherry-picking some of #5760 and using that to filter. Does that sound good @vvoland @thaJeztah?
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.
To be honest, I'd be inclined to consider function accepting
ctx
and returningcontext.Canceled
when the inputctx.Err() == nil
as buggy.A logic using
context.WithCancel
should be able to handle that in its own boundary.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.
It is fine for a function to handle its own login with
context.WithCancel
. I'm just saying when it returns an error and we check it all the way at the entry point of the program, then it shouldn't be silenced automatically.