-
-
Notifications
You must be signed in to change notification settings - Fork 625
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
Inadequate Propagation of SIGTERM and SIGINT to Task Subprocesses #1408
Comments
How about this flows?
What do you think of this idea? |
+1 Same here - the described problem prevents Docker from achieving a 'graceful exit'. |
I'm also experiencing this issue with Docker. My work around is to start the container with Here's what I do for anyone who is dealing with this for Docker: # https://taskfile.dev
version: "3"
vars:
IMAGE_NAME: my-app
IMAGE_TAG: latest
IMAGE: "{{.IMAGE_NAME}}:{{.IMAGE_TAG}}"
tasks:
default:
desc: Shows this help message
cmds:
- task --list-all
build:
desc: Build the app
cmds:
- docker build . -t {{.IMAGE}}
start:
desc: Start the app
deps:
- build
cmds:
- cmd: task stop
ignore_error: true
- docker run -d --rm -p 8080:8080 --name my-app {{.IMAGE}}
- cmd: docker logs --follow my-app
ignore_error: true
stop:
desc: Stop the app
cmds:
- docker stop my-app |
The signal handling is consuming these signals. You could try an experiment and comment out this line and see if it works like you expect. Or, an alternative might be to send a different signal and see if that gets propagated. For instance, HUP as follows:
and then you need a program that catches that ... basic idea here https://gobyexample.com/signals. The actual process that Task runs seems to come into existence here and AFAICS nothing would prevent a signal propagating through (other than they are currently consumed by Task implementation). |
I tried it without the |
Does it (Task) forward any signals to your test script? I wonder if any signals are propagated to the running shell. Possibly its achieved by cancelling the context of the shell: But it would take a bit more searching to figure out; if the signals are being propagated at all, and if not, could that effect be achieved. |
I think I found it out... There's a third signal that should be added for task's
|
Here's my demo: https://github.com/vendelin8/go-task-docker-signal |
Did you change anything in Task. As I read through the code, it seems like InterceptInterruptSignals() is delaying task from shutting down (by consuming the signal delivered to task a few times before exiting). So you implemented that part differently? |
My PR didn't seem to work, but I found out about https://github.com/krallin/tini . It propagates signals to all subprocesses with
|
Additional explanations here : https://www.kaggle.com/code/residentmario/best-practices-for-propagating-signals-on-docker Docker doc offers specific details and examples : https://docs.docker.com/reference/dockerfile/#entrypoint |
Script:
signal-test.sh
Task Configuration:
Taskfile.yml
Given the process structure:
When executing kill -INT 2, the following output is observed:
It is critical to note that the SIGINT signal fails to reach the subprocess. This issue is particularly problematic when using Taskfile within a Docker container. Both
docker stop
and CTRL-C interruption duringdocker run
attempt to send SIGINT or SIGTERM to the Taskfile process directly. The described problem prevents Docker from achieving a 'graceful exit'.The text was updated successfully, but these errors were encountered: