cmd/docker: add cause to user-terminated context.Context#5760
cmd/docker: add cause to user-terminated context.Context#5760Benehiko merged 1 commit intodocker:masterfrom
context.Context#5760Conversation
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
fayazkhan121
left a comment
There was a problem hiding this comment.
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: BeforeAfterIMO, 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
| type errCtxSignalTerminated struct { | ||
| signal os.Signal | ||
| } | ||
|
|
||
| func (e errCtxSignalTerminated) Error() string { | ||
| return "" | ||
| } |
There was a problem hiding this comment.
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.
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.Contexterror when the user terminates the process through SIGINT/SIGTERM.This allows us to distinguish the cause of the
context.Contextcancellation. 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)