-
-
Notifications
You must be signed in to change notification settings - Fork 354
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
Fix docker graceful shutdown #830
Fix docker graceful shutdown #830
Conversation
This notably ensures that "docker stop" sends a TERM signal to the node process which can handle it gracefully and avoid document corruption.
Without that, the node process will hang until docker kills the container.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @fflorent . In my understanding (and limited testing), just the second change is sufficient. Are you seeing something different? In particular, do you see a scenario where the server is logging "Server ... exiting on SIGTERM" and then not exiting promptly?
If the server isn't seeing SIGTERM, I ran into this when testing the second change on grist-omnibus -- it was helpful but not sufficient because there was an extra sh
process, that wasn't passing along the SIGTERM from docker. To get rid of that in grist-omnibus
, I had to change the command from /grist/run.js
to ["node", "/grist/run.js"]
. Just sharing in case something similar is affecting other setups.
Hi @dsagal
Does the "second change" refer to this commit: a6259aa?
Yes, exactly: SIGTERM with
A tip we use in order to test that fix: $ yarn build:prod
$ cp ./sandbox/run.sh ./sandbox/run2.sh # Not sure about that… someone in our team told us this avoids using the previous version of run.sh in the image
$ docker run --rm -v $(pwd):/grist -p 8484:8484 --name grist_latest gristlabs/grist:latest /grist/sandbox/run2.sh and then either try ctrl-c or docker stop. |
Also I just installed docker version 25.0.1 (following this procedure), I've got the same problem. |
Thanks for the more details @fflorent . I learned something new today about running things in docker! The reason I was looking to avoid Turns out, the reason is that the main container process with PID 1 is special and cannot be killed from inside a container. I found a good explanation at https://daveiscoding.com/why-do-you-need-an-init-process-inside-your-docker-container-pid-1. The recommendation there is to run docker with The other option is to keep your change, and address my concern by setting the process exit code to the expected one. This is possible with this tweak (in place of
The @paulfitz or @fflorent , do either of you have an opinion about the preferred approach? I'd be OK with either of these. |
Hello, I did some tests on a k8s cluster. If we set shareProcessNamespace: true on the deployment, we don't need the commit 0f76ada.
by
As @dsagal suggests in his comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense, thank you!
@dsagal Thank you for your review! Is it OK to merge or do you need anything beforehand? :) |
Sorry @fflorent , forgot that step again 🙂 |
Hi there, I've noticed recently that it doesn't seem possible to stop Grist with ^C anymore when it is run like this:
This is the command given in the README for people trying out Grist for the first time. @fflorent do you see this behavior too? |
I do too (I have not tested on my usual laptop, but it has to be fixed, I take the issue) |
Context
When running grist on docker, the only way to stop the node process is to kill (or wait for
docker stop
to kill the container after 10 seconds).We can see that the bash pid remains, which seems to be a bad practice
Instead we would like this situation:
Proposed solution
Here are two fixes:
run.sh
, we run node using theexec
command (this substitute the bash process with nodejs's one for pid#1
)process.kill()
withprocess.exit()
which seems to stop the server without waiting (we are not 100% sure about this fix).cc'ing @rouja @ohemelaar with whom I have pair-progged on this PR.