aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/defs_windows_amd64.go
diff options
context:
space:
mode:
authorTianon Gravi <tianon@debian.org>2019-08-14 15:19:55 +0000
committerAlex Brainman <alex.brainman@gmail.com>2019-08-29 08:15:20 +0000
commit5d1a95175e693f5be0bc31ae9e6a7873318925eb (patch)
tree5c0f0cc93f5501a356898326e86ee5b2a2142528 /src/runtime/defs_windows_amd64.go
parentd865b5caa6bedfe90ce9335af518d17f8107fb91 (diff)
downloadgo-5d1a95175e693f5be0bc31ae9e6a7873318925eb.tar.gz
go-5d1a95175e693f5be0bc31ae9e6a7873318925eb.zip
runtime: treat CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT as SIGTERM on Windows
This matches the existing behavior of treating CTRL_C_EVENT, CTRL_BREAK_EVENT as a synthesized SIGINT event. See https://docs.microsoft.com/en-us/windows/console/handlerroutine for a good documentation source upstream to confirm these values. As for the usage of these events, the "Timeouts" section of that upstream documentation is important to note, especially the limited window in which to do any cleanup before the program will be forcibly killed (defaults typically 5s, but as low as 500ms, and in many cases configurable system-wide). These events are especially relevant for Windows containers, where these events (particularly `CTRL_SHUTDOWN_EVENT`) are one of the only ways containers can "gracefully" shut down (https://github.com/moby/moby/issues/25982#issuecomment-466804071). This was verified by making a simple `main()` which implements the same code as in `ExampleNotify_allSignals` but in a `for` loop, building a `main.exe`, running that in a container, then doing `docker kill -sTERM` on said container. The program prints `Got signal: SIGTERM`, then exits after the aforementioned timeout, as expected. Behavior before this patch is that the program gets no notification (and thus no output) but still exits after the timeout. Fixes #7479 Change-Id: I2af79421cd484a0fbb9467bb7ddb5f0e8bc3610e GitHub-Last-Rev: 9e05d631b542393f5ebb0eb3747157c8bd0de635 GitHub-Pull-Request: golang/go#33311 Reviewed-on: https://go-review.googlesource.com/c/go/+/187739 Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Diffstat (limited to 'src/runtime/defs_windows_amd64.go')
-rw-r--r--src/runtime/defs_windows_amd64.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/runtime/defs_windows_amd64.go b/src/runtime/defs_windows_amd64.go
index 42a446d3cd..ebb1506e2f 100644
--- a/src/runtime/defs_windows_amd64.go
+++ b/src/runtime/defs_windows_amd64.go
@@ -15,9 +15,13 @@ const (
_DUPLICATE_SAME_ACCESS = 0x2
_THREAD_PRIORITY_HIGHEST = 0x2
- _SIGINT = 0x2
- _CTRL_C_EVENT = 0x0
- _CTRL_BREAK_EVENT = 0x1
+ _SIGINT = 0x2
+ _SIGTERM = 0xF
+ _CTRL_C_EVENT = 0x0
+ _CTRL_BREAK_EVENT = 0x1
+ _CTRL_CLOSE_EVENT = 0x2
+ _CTRL_LOGOFF_EVENT = 0x5
+ _CTRL_SHUTDOWN_EVENT = 0x6
_CONTEXT_CONTROL = 0x100001
_CONTEXT_FULL = 0x10000b