Subject: bug#42353: mcron occasionally gets stuck in pre-fork

From: Ludovic Courtès <[email-masked]>
Date: Tue, 14 Jul 2020 16:16:50 +0200

Hi,

mcron running on top of Guile 3.0.2 occasionally gets stuck right before
fork while shutting down the finalization thread:

--8<---------------cut here---------------start------------->8---
ludo@berlin ~$ ps aux|grep 25457
root      25457  0.0  0.0 149576  9412 ?        Ssl  Jul10   0:00 /gnu/store/fp5ybkawldy28kzkzp60s23hkqbdx4x2-mcron-1.1.4/bin/mcron /gnu/store/l74fbl7si93si6x47sfwsnc9ag386570-mcron-job /gnu/store/r11ffr5rfkqyw1drqrqabwx210lk1jfn-mcron-job /gnu/store/3a88kc90lv6nqy9k1bwkxpi9gps1vfdb-mcron-job /gnu/store/8386w15b7mj1pmjbp5n9jk6p2v9b0m2q-mcron-job /gnu/store/v0jwrr7ggwvr6y4xvqwiqksbrgkmm21c-mcron-job /gnu/store/wzv96j9c1h86kfzl5ai64j1xwvkin1wz-mcron-job /gnu/store/kz93w89b7sj6gz32aq6flsy0pa3ag6ny-mcron-job /gnu/store/4jv4ap1d161dvix472j47lipvqafqrmn-mcron-job /gnu/store/r7vs7vkid8w1xz0nzkcwc6ylmz8yryc5-mcron-job /gnu/store/yy51bjcx0zndsn9db56sb2d1bn7c9j1i-mcron-job /gnu/store/56vfqmzfidcf1axh07zak2gfbgrc8jdm-mcron-job
ludo     130462  0.0  0.0   6376  2476 pts/11   S+   16:10   0:00 grep --color 25457
ludo@berlin ~$ sudo gdb -ix ~/.gdbinit -p 25457
GNU gdb (GDB) 8.3.1

[…]

(gdb) bt
#0  0x00007f38221a1517 in __pthread_clockjoin_ex ()
   from /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libpthread.so.0
#1  0x00007f38222960d8 in stop_finalization_thread () at finalizers.c:276
#2  0x00007f38222962f9 in scm_i_finalizer_pre_fork () at finalizers.c:301
#3  0x00007f382231e1d6 in scm_fork () at posix.c:1230
#4  0x00007f38193b2def in ?? ()
#5  0x00007f3821bc9d80 in ?? ()
#6  0x00007f38223795c0 in ?? ()
   from /gnu/store/18hp7flyb3yid3yp49i6qcdq0sbi5l1n-guile-3.0.2/lib/libguile-3.0.so.1
#7  0x00007f3821bc9d80 in ?? ()
#8  0x00007f38222b2f0b in scm_jit_enter_mcode (thread=0x7f3821bc9d80,
    mcode=0x7f38193accd2 "I\211\314I)\304I\203\374\060\017\214s\003")
    at jit.c:5777
#9  0x00007f382230e350 in vm_regular_engine (thread=0x7f38193b2dd0)
    at vm-engine.c:546
#10 0x00007f382230f175 in scm_call_n (proc=<optimized out>,
    argv=argv@entry=0x7ffd8ff6ad58, nargs=nargs@entry=1) at vm.c:1608
#11 0x00007f382228c078 in scm_call_1 (proc=<optimized out>,
    arg1=<optimized out>) at eval.c:496
#12 0x000000000040130c in inner_main ()
#13 0x00007f38222a4c0d in invoke_main_func (body_data=0x7ffd8ff6b240)
    at init.c:308

[…]

(gdb) thread apply all bt
Thread 17 (Thread 0x7f3819c7d700 (LWP 15795)):
#0  0x00007f38221aa0a4 in read () from /gnu/store/fa6wj5bxkj5ll1d7292a70knmyl7a0cr-glibc-2.31/lib/libpthread.so.0
#1  0x00007f3822296067 in read_finalization_pipe_data (data=0x7f3819c7ca30) at finalizers.c:205
#2  0x00007f38221e8d94 in GC_do_blocking_inner () from /gnu/store/zg126cjicrpm2p6zc08ra5vh4ddag7ww-libgc-8.0.4/lib/libgc.so.1
#3  0x00007f38221e59c2 in GC_with_callee_saves_pushed () from /gnu/store/zg126cjicrpm2p6zc08ra5vh4ddag7ww-libgc-8.0.4/lib/libgc.so.1
#4  0x00007f38221e5a6c in GC_do_blocking () from /gnu/store/zg126cjicrpm2p6zc08ra5vh4ddag7ww-libgc-8.0.4/lib/libgc.so.1
#5  0x00007f38223036b5 in scm_without_guile (func=0x7f3822296050 <read_finalization_pipe_data>, data=0x7f3819c7ca30) at threads.c:706
#6  0x00007f382229641b in finalization_thread_proc (unused=<optimized out>) at finalizers.c:218
--8<---------------cut here---------------end--------------->8---

This reminds me of <https://issues.guix.info/31925> and more recently
this issue Mathieu reported: <https://issues.guix.gnu.org/41948>.

It could be that Guile still has troubles shutting down the finalization
thread.

Ludo’.