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

runtime: treat CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT, CTRL_SHUTDOWN_EVENT as SIGTERM on Windows #33311

Closed
wants to merge 1 commit into from

Conversation

tianon
Copy link
Contributor

@tianon tianon commented Jul 26, 2019

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 (moby/moby#25982 (comment)).

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

@googlebot googlebot added the cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. label Jul 26, 2019
@gopherbot
Copy link
Contributor

This PR (HEAD: e184f33) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/187739 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
Within the next week or so, a maintainer will review your change and provide
feedback. See https://golang.org/doc/contribute.html#review for more info and
tips to get your patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11, it means that this CL will be reviewed as part of the next development
cycle. See https://golang.org/s/release for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 1:

(2 comments)

Thank you for working on this.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Tianon Gravi:

Patch Set 1:

(2 comments)

Thanks for the review! :D


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. and removed cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. labels Jul 29, 2019
@gopherbot
Copy link
Contributor

This PR (HEAD: eac2d56) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/187739 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. and removed cla: no Used by googlebot to label PRs as having an invalid CLA. The text of this label should not change. labels Jul 29, 2019
@gopherbot
Copy link
Contributor

This PR (HEAD: 4e85db2) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/187739 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Tianon Gravi:

Patch Set 4: Commit message was updated.


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 6:

(3 comments)

Looks better now. Thank you very much.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 6:

Ian,

Are you OK with this CL mapping CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT onto syscall.SIGTERM ? That was what people suggested on #7479 but I know nothing about these things. Should we have wider discussion about this?

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 6:

Are you OK with this CL mapping CTRL_CLOSE_EVENT, CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT onto syscall.SIGTERM ? That was what people suggested on #7479 but I know nothing about these things. Should we have wider discussion about this?

I haven't really looked at the CL, but I'm fine with the idea of mapping those Windows events to SIGTERM (for the 1.14 release).


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Tianon Gravi:

Patch Set 6:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 318eda8) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/187739 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Tianon Gravi:

Patch Set 7:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 7:

(2 comments)

Getting there. Thank you.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

…NT 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 (moby/moby#25982 (comment)).

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 golang#7479
@gopherbot
Copy link
Contributor

This PR (HEAD: 9e05d63) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/187739 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link
Contributor

Message from Tianon Gravi:

Patch Set 8:

(1 comment)

Updated!


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from paul deauna:

Patch Set 8:

Then>resume where safe


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 8: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 8:

TryBots beginning. Status page: https://farmer.golang.org/try?commit=efd7cf48


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gobot Gobot:

Patch Set 8: TryBot-Result+1

TryBots are happy.


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 8:

This CL LGTM. Thank you very much.

I will submit this CL once Go tree opens for submission as per

https://groups.google.com/d/msg/golang-dev/UQOSRilopzw/Xtth3MQmAgAJ

Feel free to ping me here, so I don't forget.

Alex

RELNOTE=yes


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Tianon Gravi:

Patch Set 8:

Feel free to ping me here, so I don't forget.

Friendly ping? :)

(https://groups.google.com/d/msg/golang-dev/YMw7aBRvk-4/z-t2bIaaAwAJ)


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

gopherbot pushed a commit that referenced this pull request Aug 29, 2019
…NT 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 (moby/moby#25982 (comment)).

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: 9e05d63
GitHub-Pull-Request: #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>
@gopherbot
Copy link
Contributor

Message from Alex Brainman:

Patch Set 8: Code-Review+2

Friendly ping? :)

Thank you for reminding me. I will try and submit your change.

Alex


Please don’t reply on this GitHub thread. Visit golang.org/cl/187739.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR is being closed because golang.org/cl/187739 has been merged.

@gopherbot gopherbot closed this Aug 29, 2019
@tianon tianon deleted the windows-events branch August 29, 2019 13:42
tomocy pushed a commit to tomocy/go that referenced this pull request Sep 1, 2019
…NT 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 (moby/moby#25982 (comment)).

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 golang#7479

Change-Id: I2af79421cd484a0fbb9467bb7ddb5f0e8bc3610e
GitHub-Last-Rev: 9e05d63
GitHub-Pull-Request: golang#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>
t4n6a1ka pushed a commit to t4n6a1ka/go that referenced this pull request Sep 5, 2019
…NT 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 (moby/moby#25982 (comment)).

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 golang#7479

Change-Id: I2af79421cd484a0fbb9467bb7ddb5f0e8bc3610e
GitHub-Last-Rev: 9e05d63
GitHub-Pull-Request: golang#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

os, runtime: CTRL_CLOSE_EVENT should generate SIGTERM on Windows
3 participants