-
Notifications
You must be signed in to change notification settings - Fork 182
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
Support for graceful shutdown #269
Comments
Hello @mjh-c , I made a little POC to test your question here: https://gist.github.com/babelouest/685e16e26047e9d47c4ec699695817ec In short, it's possible to make a grateful shutdown, like in the gist, which works, but is not perfect. Basically, I use a The problem with this code is that when a I think I've achieved something similar in taliesin to gracefully close all websockets connections and clean the resources, see here for example. I use a combination of a counter incremented when a client connects, the counter is decremented when the client disconnects (the counter is protected by a mutex to avoid race conditions), then when the client decreases the counter, it sends another signal. If the To avoid new clients during shutdown, you can set another variable shared between the Anyway, your request seems possible, although you have to play with a few mutexes and conditions, but I don't see why not. Hope I helped! |
First of all, thank you for the effort. I also did some more investigation and I tried to solve it by implementing my own MHD_OPTION_NOTIFY_COMPLETED function that calls then the ulfius mhd_request_completed at the end. Using this hook I know for sure if an API is really finished, i.e. the response was sent back to the client by the microhttpd layer. So I can wait a certain amount of time for APIs to be completed which is an important part of "graceful" behavior from client perspective. One drawback is that I have to call ulfius_start_framework_with_mhd_options which is not really handy. With this extension I don't need to copy the whole ulfius_run_mhd_daemon handling of MHD options and flags in my application code and keep it in sync with upcoming versions. The handling of immediately sending a 503 when in shutdown phase I implemented already like you suggested. Thanks for confirming. For the synchronization of main and MHD threads I use shared volatile variables which is not elegant. I will have a look on your pthread_cond_t changes if it makes sense to replace that. |
Does ulfius / microhttpd support a graceful shutdown of a service? I am thinking about the following scenario:
The goal is to be as friendly as possible to clients and proxies:
I haven't found any ulfius examples that cover this. Is this something that could be supported in ulfius or implemented by the application?
The text was updated successfully, but these errors were encountered: