-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
How to handle startup failure in custom Worker? #2867
Comments
why would you do that? the application should be stable enough so such error should no( be catched before it starts. Let it crash and cfix the error should be the rule there. Hacking around in the worker would just hide the error. Known exception themselves need to be catched by the application. Gunicorn itself offer a way to test the configuration and start the application uysing the command line. |
if you really want to provide a different level, then you can sys exit with a custom error code if needed. But i thing logging and letting it crash would be safer and easier to fix. |
Please see the linked PR (I'm not the one using or having issues with Gunicorn, I just want to know what we're expected to do, if anything):
I did find there is an |
To be clear, we're talking about what the correct implementation should be for the aiohttp worker, which looking through git history actually lived in this repository a few years ago. |
I guess we'll just take an educated guess then.. |
what do you mean? I answered to the details provided there. Just let it crash and don't try to be smart and catch mre error than needed in your worker. ie don't catch apps error and co. this is what is actually done. the arbiter will catch the exit code. If you want to provide a cust exit code then pass it via sys.exit. If you want more details then please add the needed info there. I will reopen the ticket since you seem to expect more but please describe more precisely what part you're missing. |
As pointed out in my previous comments, I'm under the impression you are talking about changes to a specific app, but I'm asking about changes to a worker implementation used by hundreds of apps (which used to be maintained in this repo). I figured you'd probably be in the best place to review the proposed change (as asvetlov is not really available currently), and linked the PR at the top. I was hoping you'd take 5 mins to look at it and confirm if that makes sense or not. Otherwise, I'm just making an educated guess on the correct behaviour, as I have no familiarity with gunicorn implementation. |
I was talking about workers. See what is done in the simpler sync worker to load the application: gunicorn/gunicorn/workers/base.py Lines 144 to 165 in 506d014
If application would not load it would simply crash the spawned worker and be catched by the arbiter since the loader would have raised the exception AppImportError via the util function: Line 371 in 506d014
And then to tell to the arbiter the worker booted it's really simple, self.booted need to be set to true or false if booted:
gunicorn/gunicorn/workers/base.py Line 141 in 506d014
For others error it is just raising exeception. Only signals set the sys._exit. BOOT and APP_LOAD_ERROR are set by the arbiter: Lines 605 to 631 in 506d014
Hope this helps. |
updated previous comment for clarity. |
Wait, in run() it currently catches all exceptions and then exits with a 0 exit code: Should that be completely changed and just allow exceptions to be raised instead? Or am I misunderstanding that? Seem like it already did that originally, but received updates as if that wasn't the desired behaviour: |
To clarify, generally speaking the worker should only catch the errors related to its own activity but raise when application is failing to load or is erroring. Once the worker is booted, ie. ready to accept requests it should set worker.booted to true. Exit when expected (signaling) should exit with the codde 0. If I get sometimes today I will check your code but you have the idea :) |
no activity since awhile. closing feel free to create a new ticket if needed. |
It would be great if anyone could provide some feedback on how a custom worker is meant to handle an exception when starting up the application. Please take a look at this PR, where it has been suggested that this should become a
WORKER_BOOT_ERROR
, and my comments: aio-libs/aiohttp#6968Any feedback on correct handling would be greatly appreciated.
The text was updated successfully, but these errors were encountered: