Skip to content
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

Async logger crash after fork() #166

Closed
hzhaop opened this issue Jan 22, 2016 · 8 comments
Closed

Async logger crash after fork() #166

hzhaop opened this issue Jan 22, 2016 · 8 comments

Comments

@hzhaop
Copy link

hzhaop commented Jan 22, 2016

Here is my situation:
A main process have a global async logger, and then it will fork several subprocesses.
When the subprocess call log function of the global async logger, the process dead because the _worker_thread in the new process is no longer the thread in the main process.

Maybe we can do some cleanup when _worker_thread::id != this_thread::get_id() or so?

Thanks.

@gabime
Copy link
Owner

gabime commented Jan 22, 2016

spdlog does not support multi process. I dont think there is a quick workaround

@bumbar1
Copy link

bumbar1 commented Feb 18, 2016

Does that mean I can't use spdlog in daemon?

@gabime
Copy link
Owner

gabime commented Feb 18, 2016

it depends which type of daemon of course

@bumbar1
Copy link

bumbar1 commented Feb 18, 2016

I'm working on a server (reading data through socket), and it's crashing when I run in as daemon. Are there any special steps I should be taking, in regards to spdlog library?

@gabime
Copy link
Owner

gabime commented Feb 19, 2016

make sure you create the loggers after the fork

@bumbar1
Copy link

bumbar1 commented Feb 19, 2016

I have logger declared in global scope as std::shared_ptr<spdlog::logger> logger, then I do the daemonization process (fork, setsid, closing stdin, stdout and stderr) and after that I create a temporary logger and assign it to logger. When I try call logger->info(...) it crashes with segfault. I'm using syslog and file logger, if it makes any difference.

@bumbar1
Copy link

bumbar1 commented Feb 21, 2016

I managed to got it working, but seems I have to manually call flush when writing to file log. Is there some option I missed, or is that part of library's behavior?

@gabime
Copy link
Owner

gabime commented Feb 21, 2016

there is a force_flush param you can use. please see the docs

@gabime gabime closed this as completed Feb 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants