Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

多线程环境,fork后的子进程中,如果继续使用log记录日志,有几率出现死锁 #62

Closed
lisongmin opened this issue May 28, 2014 · 5 comments

Comments

@lisongmin
Copy link

pid = fork()
if (pid == 0)
{
log_info("test."); // 这里可能会造成死锁
}

执行fork的时候,如果有别的线程已经加了写锁,fork后的子进程也会处于写锁的状态,
这个时候,子进程再写日志,会出现死锁。

现在规避的方案是fork后,子进程不要调用log记录日志,不知道是否还有更好的方法

@HardySimpson
Copy link
Owner

写锁只在重新加载配置的时候才用,这种概率你都碰上了?

@lisongmin
Copy link
Author

应该不是加载配置,我用的是1.2.9版本的,阻塞的地方在这里:
#0 0x00007f18a135b89c in __lll_lock_wait () from /lib/x86_64-linux-gnu/libpthread.so.0
#1 0x00007f18a13582e1 in pthread_rwlock_rdlock () from /lib/x86_64-linux-gnu/libpthread.so.0
#2 0x00007f189fe589f9 in dzlog (file=0x7f18a111dfe8 " SubProcess.cpp", filelen=54, func=0x7f18a111e0e4 "exec_on_posix", funclen=13, line=438, level=20, format=0x7f18a111df96 "arg %d: %s") at zlog/src/zlog.c:891
#3 0x00007f18a10d821b in SubProcess::exec_on_posix (this=0x7f169af3cdf0) at SubProcess.cpp:438
#4 0x00007f18a10d86d3 in SubProcess::execute (this=) at SubProcess.cpp:104
#5 0x00000000004011e1 in fnThreadFun(void*) ()
#6 0x00007f18a1354e9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#7 0x00007f18a01543fd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#8 0x0000000000000000 in ?? ()

@lisongmin
Copy link
Author

哦,是读锁阻塞住了,但整个进程都没有加载配置的地方,除了初始化,
1.2.9有自动加载配置的操作吗?

@kevin-tso
Copy link

多进程写同一日志文件支持吗

@lisongmin lisongmin closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2024
@kevin-tso
Copy link

kevin-tso commented Jul 25, 2024 via email

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants