-
Notifications
You must be signed in to change notification settings - Fork 57
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
Process fork support #138
Comments
No, the library was not designed to be fork-safe. |
huyovo |
thsito podelat ¯_(ツ)_/¯ |
Can you fix it? I've read through the code, and it seems that it's enough to remove all handlers from the root logger before fork. This will call destructors of all sinks and subsequently flush logs/join threads/close files/etc (at least for the standard sinks). |
Then it's enough to reassign the logger just before/after fork, which you can do explicitly without library support. Blackhole supports thread-safe reassignments using operator=(&&). Seriously, I haven't seen any library that was OK with forking without doing black magic around. |
I'm not sure what happens with logger's scope::manager_t after assignment. Seems to me that if I assign to the root logger while there is any watcher_t object, it will lose the scoped attributes (even segfault?). Seriously, nginx does fork. Is this library not supposed to be used in programs like nginx? |
I didn't test. Be the first! |
It's not about testing, it's about how it's supposed to be. But anyway, I wrote a test:
Looks bad. Some other way to remove/restore handlers is required. Also it's not enough to just make something that works. The point is whether the library declares support of forking or not. Because if it's not guaranteed that the reassignment approach will continue to work, it's not useful. |
Looks as expected: https://github.com/3Hren/blackhole/blob/master/tests/root.cpp#L355
Ideas? What to do with scoped attributes in that case?
I'd happily declare fork-safety support when it will be done. But right now I have no idea how to implement this properly, I don't know how computers work, sorry. I know the man, who knows - @andrusha97! |
Looks bad if I want to assign to the logger before and after fork. I'm not criticizing your design :)
How about method
Why sarcasm? It's a sirious issue! Nice ava. |
Adding such method seems ok. But who creates handlers before passing to the method? |
It's a hard question. More methods are needed:
|
Well, filters can be reset right now. Handlers are not. May be just add a method, which destructs current logger into handlers? Sorry for my Rust: fn into_handlers(self) -> Vec<Box<Handler>>;
...
let handlers = logger.into_handlers(); |
It looks unnatural to me. If I didn't know about this particular case, I couldn't tell where this method might be used. |
Yep, currently we do this with |
Does blackhole support process forking?
By support I mean ability to safely perform fork() and then use the "same" root logger in both parent and child processes. Probably sinks in the child process should reconnect all sockets, reopen files, etc, because it's a bad idea to send logs through the same socket from two processes.
The text was updated successfully, but these errors were encountered: