[LBBS-128] thread.c: Recursive lock attempt between find_thread and thread_unregister
Not currently sure how this is possible, and this is the first time I've seen it:
[2026-01-26 23:59:19.760] DEBUG[2832531]: mod_mail.c:236 mailbox_dispatch_event: Dispatching mailbox event 'Logout' (maildir: )
[2026-01-26 23:59:19.760] DEBUG[2832531]: node.c:2347 bbs_node_exit: Node 51 has ended its IMAPS session
[2026-01-26 23:59:19.760] DEBUG[2832531]: node.c:641 node_shutdown: Beginning shut down of node 51
[2026-01-26 23:59:19.760] DEBUG[2832531]: event.c:143 bbs_event_broadcast: Event NODE_SHUTDOWN dispatched and not consumed
[2026-01-26 23:59:19.760] DEBUG[2832531]: event.c:143 bbs_event_broadcast: Event USER_LOGOFF dispatched and not consumed
[2026-01-26 23:59:19.760] DEBUG[2832531]: io.c:608 bbs_io_teardown_all_transformers: Removing I/O transformer at index 0
[2026-01-26 23:59:19.761] DEBUG[2832531]: thread.c:364 __bbs_pthread_join: Attempting to join thread 139898392590016 (LWP 2832532) at io.c:592 teardown_transformation()
[2026-01-26 23:59:19.761] ERROR[2832531]: thread.c:125 __thread_unregister: Recursive attempt to wrlock &thread_list, definite deadlock! (rwlock acquired at thread.c:319 0 s ago by LWP 2832531)
[2026-01-26 23:59:19.761] ERROR[2832531]: lock.c:477 __bbs_rwlock_wrlock: Failed assertion 0
[2026-01-26 23:59:19.787] ERROR[2832531]: backtrace.c:255 bbs_log_backtrace: Got 15 backtrace records
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 0: lbbs bbs_log_backtrace()
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 1: lbbs __bbs_assert_fatal()
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 2: lbbs __bbs_rwlock_wrlock()
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 3: lbbs <unknown>()
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 4: lbbs __bbs_pthread_join()
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 5: lbbs <unknown>()
[2026-01-26 23:59:20.219] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 6: lbbs bbs_io_teardown_all_transformers()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 7: lbbs bbs_io_shutdown()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 8: lbbs <unknown>()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 9: lbbs bbs_node_unlink()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 10: lbbs bbs_node_exit()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 11: [0x7f3cb1ebe387] net_imap.so net_imap.c:5117 __imap_handler()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 12: lbbs <unknown>()
[2026-01-26 23:59:20.220] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 13: [0x7f3cd63351f5] libc.so.6 pthread_create.c:442 start_thread()
[2026-01-26 23:59:20.221] ERROR[2832531]: backtrace.c:279 bbs_log_backtrace: 14: [0x7f3cd63b58dc] libc.so.6 clone3.S:83 clone3()
BBS server disconnected
#6 __bbs_rwlock_wrlock (t=0x55ed32ba8d90 <thread_list+16>, filename=0x55ed32b98e20 "thread.c", lineno=125, func=0x55ed32b993c0 <__func__.10> "__thread_unregister", name=0x55ed32b98e29 "&thread_list") at lock.c:>
diff = 0
res = 16
c = 1
now = 1769471959
elapsed = 0
start = 1769471959
__func__ = "__bbs_rwlock_wrlock"
#7 0x000055ed32b7dc44 in __thread_unregister (id=139898392590016, file=0x55ed32b8d6da "io.c", line=592, func=0x55ed32b8df30 <__func__.6> "teardown_transformation") at thread.c:125
x = 0x7f3cb1632980
remove = 0
lwp = -1
__func__ = "__thread_unregister"
#8 0x000055ed32b7ec94 in __bbs_pthread_join (thread=139898392590016, retval=0x0, file=0x55ed32b8d6da "io.c", func=0x55ed32b8df30 <__func__.6> "teardown_transformation", line=592) at thread.c:414
Here is another instance. This basic issue (recursive lock error when a thread exits, in thread_unregister) has happened several times before. This seems more likely to happen when a thread has a very short lifetime, i.e. it is spawned and almost immediately exits.
[2026-03-05 13:10:54.171] DEBUG[3840181]: io.c:267 io_transform_store: Set up I/O transformer at index 1
[2026-03-05 13:10:54.171] DEBUG[3840181]: net_imap.c:4974 imap_process: 0x7f64827cb840 <= DU3 OK DEFLATE active
[2026-03-05 13:10:54.172] DEBUG[3840183]: thread.c:106 thread_register: Thread 3840183 spawned from io_thread started by thread 3840181 at io.c:434 bbs_io_transform_setup()
[2026-03-05 13:10:54.217] DEBUG[3840181]: net_imap.c:5053 handle_client: 0x7f64827cb840 => DU4 NAMESPACE
...
[2026-03-05 13:10:54.225] DEBUG[3840181]: net_imap.c:1913 handle_list: 0x7f64827cb840 <= DU5 OK LIST completed.
[2026-03-05 13:10:54.265] DEBUG[3840182]: io_tls.c:230 io_read: SSL_read returned 0: SSL_ERROR_ZERO_RETURN
[2026-03-05 13:10:54.266] DEBUG[3840182]: io.c:368 io_thread: TLS I/O thread exiting
[2026-03-05 13:10:54.266] DEBUG[3840183]: io.c:358 io_thread: poll(pfds[0]) returned POLLHUP (fd 792)
[2026-03-05 13:10:54.266] DEBUG[3840183]: io.c:368 io_thread: DEFLATE I/O thread exiting
[2026-03-05 13:10:54.266] ERROR[3840183]: thread.c:125 __thread_unregister: Recursive attempt to wrlock &thread_list, definite deadlock! (rwlock acquired at thread.c:102 0 s ago by LWP 3840183)
[2026-03-05 13:10:54.267] ERROR[3840183]: lock.c:508 __bbs_rwlock_wrlock: Failed assertion 0
[2026-03-05 13:10:54.507] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 0: lbbs bbs_log_backtrace()
[2026-03-05 13:10:54.507] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 1: lbbs __bbs_assert_fatal()
[2026-03-05 13:10:54.508] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 2: lbbs __bbs_rwlock_wrlock()
[2026-03-05 13:10:54.508] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 3: lbbs <unknown>()
[2026-03-05 13:10:54.508] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 4: lbbs <unknown>()
[2026-03-05 13:10:54.508] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 5: lbbs <unknown>()
[2026-03-05 13:10:54.508] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 6: [0x7f64c88a71f5] libc.so.6 pthread_create.c:442 start_thread()
[2026-03-05 13:10:54.509] ERROR[3840183]: backtrace.c:279 bbs_log_backtrace: 7: [0x7f64c89278dc] libc.so.6 clone3.S:83 clone3()
BBS server disconnected
#5 0x00005603acd36755 in __bbs_assert (function=0x5603acd74da0 <__func__.3> "__bbs_rwlock_wrlock", line=508, file=0x5603acd74198 "lock.c", condition_str=0x5603acd7420b "0", condition=0) at ../include/bbs.h:437
diff = 0
res = 16
c = 1
now = 1772716254
elapsed = 0
start = 1772716254
__func__ = "__bbs_rwlock_wrlock"
#6 __bbs_rwlock_wrlock (t=0x5603acd8ed90 <thread_list+16>, filename=0x5603acd7eec0 "thread.c", lineno=125, func=0x5603acd7f460 <__func__.10> "__thread_unregister", name=0x5603acd7eec9 "&thread_list") at lock.c:508
diff = 0
res = 16
c = 1
now = 1772716254
elapsed = 0
start = 1772716254
__func__ = "__bbs_rwlock_wrlock"
#7 0x00005603acd6405e in __thread_unregister (id=140069855704768, file=0x0, line=0, func=0x0) at thread.c:125
x = 0x2b0000038f
remove = 0
lwp = -1
__func__ = "__thread_unregister"
#8 0x00005603acd646fd in thread_unregister (id=0x7f648dfe36c0) at thread.c:232Comments
You must be logged in to leave a comment.
3/10/2026 5:10 PM — InterLinked
Autoresolved by code commit on GitHub:
lock.c: Lock internal mutex when checking for recursive lock attempt.
https://github.com/InterLinked1/lbbs/commit/a0b082818843042eccadd77f2cf54d4f3ff64ece