两次fork,第二次fork得父进程不退出
- Dominant language
- C++
- Stars
- 17.6k
- Forks
- 4.1k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 69
Description
**Describe the bug**
两次fork,第二次fork得父进程不退出
**To Reproduce**
连接brpc得程序,通过两次fork来实现daemonize,多次运行之后可以复现
**Expected behavior**
父进程能够正常退出,
**Versions**
OS: Ubuntu 22.04
Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0
brpc: 1.15.0
protobuf: tag: v3.25.5
**Additional context/screenshots**
`
[New LWP 437932]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
0x00007faab40873f0 in __lll_lock_wait () from /lib64/libc.so.6
Thread 2 (Thread 0x7faab3e79640 (LWP 437932) "bvar_sampler"):
#0 0x00007faab40d4655 in clock_nanosleep@GLIBC_2.2.5 () from /lib64/libc.so.6
#1 0x00007faab40d9247 in nanosleep () from /lib64/libc.so.6
#2 0x00007faab41050f9 in usleep () from /lib64/libc.so.6
#3 0x00000000015f98ba in bvar::detail::SamplerCollector::run (this=this@entry=0x4d270f0) at /dingo-eureka/brpc/src/bvar/detail/sampler.cpp:183
#4 0x00000000015fb7f0 in bvar::detail::SamplerCollector::sampling_thread (arg=0x4d270f0) at /dingo-eureka/brpc/src/bvar/detail/sampler.cpp:113
#5 0x00007faab408a19a in start_thread () from /lib64/libc.so.6
#6 0x00007faab410f210 in clone3 () from /lib64/libc.so.6
Thread 1 (Thread 0x7faab4227280 (LWP 437931) "dingo-client"):
#0 0x00007faab40873f0 in __lll_lock_wait () from /lib64/libc.so.6
#1 0x00007faab408d582 in pthread_mutex_lock@@GLIBC_2.2.5 () from /lib64/libc.so.6
#2 0x00000000015f9546 in butil::Mutex::lock (this=0x4f5c470) at /dingo-eureka/brpc/src/butil/synchronization/lock.h:74
#3 bvar::detail::Sampler::destroy (this=0x4f5c450) at /dingo-eureka/brpc/src/bvar/detail/sampler.cpp:214
#4 0x00000000005616eb in bvar::PassiveStatus::~PassiveStatus (this=0x3f22c00 , __in_chrg=) at /root/.local/dingo-eureka/include/bvar/passive_status.h:112
#5 0x00007faab40412dd in __run_exit_handlers () from /lib64/libc.so.6
#6 0x00007faab4041430 in exit () from /lib64/libc.so.6
#7 0x0000000000555bef in dingofs::utils::Daemonize (chdir_root=, close_fds=) at /opt/dingofs/src/utils/daemonize.h:34
#8 0x0000000000521fb6 in main (argc=, argv=) at /opt/dingofs/src/client/main.cc:195
`
Contributor guide
Research direction
Start with utils/daemonize.h and client/main.cc, then inspect bvar/detail/sampler.cpp and butil/synchronization/lock.h around the mutex wait shown in the stack trace. Reproduce the two-fork daemonization case on Ubuntu 22.04 and confirm that the parent exits without hanging during sampler cleanup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, linux
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100