-
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
cmd/docker: add cause to user-terminated context.Context
#5760
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5760 +/- ##
==========================================
- Coverage 59.47% 59.43% -0.04%
==========================================
Files 346 347 +1
Lines 29367 29431 +64
==========================================
+ Hits 17465 17492 +27
- Misses 10929 10965 +36
- Partials 973 974 +1 |
8839f12
to
bdd630c
Compare
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.
The test looks solid. TestUserTerminatedError
test case properly introduces notifyContext
and handles the termination signals as expected.
1cad6c0
to
da5701e
Compare
Please don't merge yet, this is incorrect. We need to have status 130 print when a container exits with that code. |
da5701e
to
bdd630c
Compare
577e0d2
to
4e7cf34
Compare
Spam / AI account (blocked now)
4e7cf34
to
8e41a36
Compare
LGTM overall, but we probably still need to adjust the output, see: Before
After
IMO, it shouldn't print anything at all, so it should look like:
|
8e41a36
to
9f41558
Compare
This patch adds a "cause" to the `context.Context` error when the user terminates the process through SIGINT/SIGTERM. This allows us to distinguish the cause of the `context.Context` cancellation. In future we would also be able to improve the UX of printed errors based on the underlying cause. Signed-off-by: Alano Terblanche <[email protected]> cmd/docker: fix possible race between ctx channel and signal channel Signed-off-by: Alano Terblanche <[email protected]> test: notifyContext Signed-off-by: Alano Terblanche <[email protected]> cmd/docker: print status on SIGTERM and not SIGINT Signed-off-by: Alano Terblanche <[email protected]>
9f41558
to
c51be77
Compare
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.
LGTM
type errCtxSignalTerminated struct { | ||
signal os.Signal | ||
} | ||
|
||
func (e errCtxSignalTerminated) Error() string { | ||
return "" | ||
} |
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.
Just a small nit/suggestion, not necessary.
You could do:
type errCtxSignalTerminated struct { | |
signal os.Signal | |
} | |
func (e errCtxSignalTerminated) Error() string { | |
return "" | |
} | |
type errCtxSignalTerminated struct { | |
signal os.Signal | |
} | |
func (e *errCtxSignalTerminated) Error() string { | |
return "" | |
} | |
func (e *errCtxSignalTerminated) exitCode() int { | |
if e == nil { | |
return 1 | |
} | |
s, ok := e.signal.(syscall.Signal) | |
if !ok { | |
return 1 | |
} | |
return 128 + int(s) | |
} |
Then errCtxSignalTerminated
implements error
(instead of *errCtxSignalTerminated
implementing error
.
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.
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.
+1 on the exitCode
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.
The suggestion looks alright to me, although we only use the exit code inside the getExitCode
function and this error type is only used inside cmd/docker/docker.go
. At least to me, it just seems like extra refactoring with little benefit.
This patch adds a "cause" to the
context.Context
error when the user terminates the process through SIGINT/SIGTERM.This allows us to distinguish the cause of the
context.Context
cancellation. In future we would also be able to improve the UX of printed errorsbased on the underlying cause.
- What I did
- How I did it
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)