Skip to content

Catch SIGTERM on default settings. #24

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

weezel
Copy link

@weezel weezel commented Mar 25, 2025

This is useful with services like AWS Fargate where SIGTERM is sent when container is being stopped [1]. Can drastically speed up the shutdown and most importantly does it gracefully.

Caveats: won't work on Windows.

[1] https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/

Copy link
Contributor

@heppu heppu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good addition! Before merging this:

  1. change the comment line to reflect new defaults
  2. add test case for default option sigterm usage

For the test case, you could modify the TestListener by adding inputSig syscal.Signal field and then use that.

Copy link

codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@weezel weezel force-pushed the hanle_sigterm_by_default branch 2 times, most recently from b0725f1 to 6057ee9 Compare March 27, 2025 21:16
@weezel
Copy link
Author

weezel commented Mar 27, 2025

This is a good addition! Before merging this:

1. change the comment line to reflect new defaults

2. add test case for default option sigterm usage

For the test case, you could modify the TestListener by adding inputSig syscal.Signal field and then use that.

Thanks for the input. Now with the tests included and comment modified.

@weezel weezel force-pushed the hanle_sigterm_by_default branch from 6057ee9 to 0205cd5 Compare March 27, 2025 21:18
This is useful with services like AWS Fargate where SIGTERM is sent when
container is being stopped [1]. Can drastically speed up the shutdown
and most importantly does it gracefully.

Caveats: won't work on Windows.

[1] https://aws.amazon.com/blogs/containers/graceful-shutdowns-with-ecs/

Signed-off-by: Ville Valkonen <[email protected]>
@weezel weezel force-pushed the hanle_sigterm_by_default branch 2 times, most recently from fd5bd2c to 73fdc83 Compare March 27, 2025 21:20
signals = []os.Signal{os.Interrupt}
signals = []os.Signal{
os.Interrupt,
syscall.SIGTERM, // XXX Not available on Windows
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely forgot this windows aspect. I will test this on windows and come back with comments.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this will continue to work on Windows even there's no mapping for it.

@heppu
Copy link
Contributor

heppu commented Apr 9, 2025

Finally got windows machine to implement working win support #25 and now the code uses proper build constraints to achieve win/unix compatibility.

If you rebase the pr you should be able to add sigterm only for unix platfors here and here .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants