-
Notifications
You must be signed in to change notification settings - Fork 138
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
Document if Sender is fork-safe. #60
Comments
It depends on Python's socket implementation. |
I'm interested in this as well, having some issues getting async handler sending to a remote fluentd host with a basic gunicorn + Django deployment |
|
Generally-speaking NO threaded application is fork-safe. Forks and threads are not compatible as POSIX mandates killing all threads upon forking. Sync sender should be safe. |
If you want the fD survive you will need to make sure the worker inherit from it at the system level. This can be done similarly to what does the logging handler. |
This turned out to be the cause of a hang I was seeing in the following setup:
If the celery worker parent process has done any logging before it forked the child workers, then the handler in the parent process will have constructed its async sender (which starts its thread) - so then all future child celery worker processes have a handler with a broken asyncsender (no thread) which causes the following symptoms:
Initially this only happened when I had certain log levels configured (resulting in early logging in the celery parent) but actually if anything is ever logged in the parent, then after that point if any child worker dies (e.g. OOM killer) or is recycled (by celery |
I think it would be worthwhile documenting the risk of using this with anything that does fork and perhaps explicitly mentioning celery given it could be a common use case. Also I wonder if if not self._send_thread.is_alive():
print(f'WARNING async FluentSender thread in pid={os.getpid()} is not alive', file=sys.stderr) or possibly even automatically start the thread again (which would avoid the bug)? Or another option would be to use I'm happy to open a PR for any of the above suggestions if you think they are acceptable changes. |
Consider a scenario where:
Will the socket get cloned or reopened?
Does fluent logger expect a response from fluentd?
If it does, can the response be read out by wrong sender process?
The text was updated successfully, but these errors were encountered: