-
Notifications
You must be signed in to change notification settings - Fork 479
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
Add graceful shutdown #944
Conversation
Resolves #395.
Thank you for this PR, but I think we should still discuss what kind of graceful shutdown we actually want. Citing from Go's docs about
This means that with your PR, tusd will wait 5s for all HTTP requests to complete. If there are still open requests after this timeout, it will stop the process without closing them properly. Given that tusd handles uploads, there is a fair share of requests that will be running longer than 5s. For some data stores (e.g. the s3 store), interrupting the request handling could lead to the loss of data that is in currently in a buffer. Of course, it will be retransmitted once tusd is back up, but it would be great if we could gracefully shut down PATCH requests as well and allow the buffers to be flushed to S3. Does that make sense? |
👋 @Acconut. Yes, that makes perfect sense 👍 I'll take a look at how |
Great, let me know if you need any help! To be honest, I am not sure if
One additional note: It is not necessary to directly flush its buffers. It's enough to call |
I tried something out just for fun in the latest commit, but I am not sure it is a good way to go about it. What might be a little more straightforward is to just do a "best effort" shutdown with no context cancellation. That is, just call |
@craigpastro Thank you very much for your initial work on this! That was really helpful and I used to to implement the upload interruption in a more elegant way. Please have a look at my PR #963, which borrows some ideas from your PR here. A shutdown is initiated once signal is received. It then immediately instructs all uploads to stop. After either all connections are closed or a grace period has elapsed or a second signal is received, it will shut down immediately. The upload interruption is similar to your approach, but reuses existing code around closing the request body. Please let me know what you think! |
Hello there 👋 This is an attempt to resolve #395. Please let me know what you think. Thanks!
Sorry about the diff. I removed the early return and indented the TLS part so that the shutdown could be done at the end, which led to the rather big diff.
At the moment, the timeout is 5 seconds and not configurable. Please let me know if you would like me to add that.
Closes #395.