Skip to content

Commit 65b1641

Browse files
riptlripatel-fd
authored andcommitted
log: fix signal lock reentrancy bug
Fixes a bug in fd_log where a thread starts infinite looping if it catches a signal while already holding a log lock. This affects all regular executables (e.g. unit tests) but not fdctl.
1 parent 5ab7c09 commit 65b1641

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/util/log/fd_log.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,13 @@ fd_log_private_sig_abort( int sig,
10081008
void * context ) {
10091009
(void)info; (void)context;
10101010

1011+
/* Thread could have caught signal while holding a lock.
1012+
Hack around this re-entrancy problem by pointing the log lock to
1013+
a dummy buffer. */
1014+
int * old_lock = fd_log_private_shared_lock;
1015+
static FD_TL int lock = 0;
1016+
fd_log_private_shared_lock = &lock;
1017+
10111018
/* Hopefully all out streams are idle now and we have flushed out
10121019
all non-logging activity ... log a backtrace */
10131020

@@ -1042,6 +1049,7 @@ fd_log_private_sig_abort( int sig,
10421049

10431050
usleep( (useconds_t)1000000 ); /* Give some time to let streams drain */
10441051

1052+
fd_log_private_shared_lock = old_lock;
10451053
raise( sig ); /* Continue with the original handler (probably the default and that will produce the core) */
10461054
}
10471055

0 commit comments

Comments
 (0)