lib: fix crash in thread_process_io_inner_loop on stale epoll event - #21124
Merged
Conversation
When do_event_cancel() processes a pending cancellation at the top of event_fetch_inner_loop(), it removes the fd from the epoll_event_hash and calls EPOLL_CTL_DEL. However, epoll_wait() can still deliver events that were already queued in the kernel's ready list before the EPOLL_CTL_DEL took effect. When thread_process_io_inner_loop() processes such a stale event, the hash lookup returns NULL and the assert(hash_ev) fires, crashing the daemon. Fix: === Replace the assert with a graceful return Crash: ====== ``` Thread 4 (Thread 0x7f9ea41e89c0 (LWP 8531)): 0 0x00007f9ea449112b in ?? () from /lib/x86_64-linux-gnu/libc.so.6 1 0x00007f9ea4497482 in pthread_mutex_lock () from /lib/x86_64-linux-gnu/libc.so.6 2 0x00007f9ea471eaa5 in _frr_mtx_lock (mutex=0x5629ffcf86a8) at ../lib/frr_pthread.h:253 3 event_cancel_async (master=0x5629ffcf8580, thread=0x562a024559f8, eventobj=0x0) at ../lib/event.c:2040 4 0x00005629e3b4b15e in bgp_writes_off (connection=0x562a02455990) at ../bgpd/bgp_io.c:83 5 0x00005629e3b430ad in bgp_stop (connection=0x562a02455990) at ../bgpd/bgp_fsm.c:2065 6 0x00005629e3b48a9d in bgp_event_update (connection=connection@entry=0x562a02455990, event=TCP_connection_closed) at ../bgpd/bgp_fsm.c:3191 7 0x00005629e3c14828 in bgp_process_conn_error (event=<optimized out>) at ../bgpd/bgpd.c:9707 8 0x00007f9ea471f59a in event_call (event=event@entry=0x7fff59c62f90) at ../lib/event.c:2730 9 0x00007f9ea46bfed0 in frr_run (loop=0x5629ffb4fcd0) at ../lib/libfrr.c:1258 10 0x00005629e3af650e in main (argc=<optimized out>, argv=0x7fff59c63248) at ../bgpd/bgp_main.c:549 <SNIP> Thread 1 (Thread 0x7f9ea2be06c0 (LWP 8534)): 0 0x00007f9ea4495eec in ?? () from /lib/x86_64-linux-gnu/libc.so.6 1 0x00007f9ea4446fb2 in raise () from /lib/x86_64-linux-gnu/libc.so.6 2 0x00007f9ea470bf86 in core_handler (signo=6, siginfo=0x7f9ea2bdeb30, context=<optimized out>) at ../lib/sigevent.c:268 3 <signal handler called> 4 0x00007f9ea4495eec in ?? () from /lib/x86_64-linux-gnu/libc.so.6 5 0x00007f9ea4446fb2 in raise () from /lib/x86_64-linux-gnu/libc.so.6 6 0x00007f9ea4431472 in abort () from /lib/x86_64-linux-gnu/libc.so.6 7 0x00007f9ea473def9 in _zlog_assert_failed (xref=xref@entry=0x7f9ea4803080 <_xref.24>, extra=extra@entry=0x0) at ../lib/zlog.c:779 8 0x00007f9ea471b979 in thread_process_io_inner_loop (m=m@entry=0x5629ffcf8580, revent=0x5629ffd00740) at ../lib/event.c:2170 9 0x00007f9ea471f3c3 in thread_process_io (num=1, m=0x5629ffcf8580) at ../lib/event.c:2247 10 event_fetch_inner_loop (event=0x0, continued=<synthetic pointer>, broken=<synthetic pointer>, fetch=0x7f9ea2bdfb80, m=0x5629ffcf8580) at ../lib/event.c:2544 11 event_fetch (m=0x5629ffcf8580, fetch=fetch@entry=0x7f9ea2bdfb80) at ../lib/event.c:2559 12 0x00007f9ea46ae9e9 in fpt_run (arg=0x5629ffcf8490) at ../lib/frr_pthread.c:368 13 0x00007f9ea44941f5 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 14 0x00007f9ea45148dc in ?? () from /lib/x86_64-linux-gnu/libc.so.6 ``` Ticket: #4898763 Signed-off-by: Manpreet Kaur <manpreetk@nvidia.com>
Greptile SummaryThis PR fixes a crash in
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant OT as Other Thread
participant EL as Event Loop
participant K as Kernel (epoll)
Note over EL: event_fetch_inner_loop() begins
OT->>EL: event_cancel_async(fd)
EL->>EL: do_event_cancel(): remove fd from epoll_event_hash
EL->>K: EPOLL_CTL_DEL(fd)
Note over K: fd removed from interest list,<br/>but stale event already in ready list
EL->>K: fd_poll() / epoll_wait()
K-->>EL: returns stale event for fd
EL->>EL: thread_process_io_inner_loop(revent)
EL->>EL: hash_ev = epoll_event_hash_find(fd) β NULL
Note over EL: BEFORE fix: assert(hash_ev) β CRASH
Note over EL: AFTER fix: zlog_debug + graceful return β
Last reviewed commit: cbb00ba |
donaldsharp
reviewed
Mar 13, 2026
mjstapp
approved these changes
Mar 13, 2026
mjstapp
left a comment
Contributor
There was a problem hiding this comment.
yes, thanks, this assert was not really safe
Member
|
@Mergifyio backport stable/10.6 |
β Backports have been createdDetails
|
Jafaral
added a commit
that referenced
this pull request
Mar 14, 2026
lib: fix crash in thread_process_io_inner_loop on stale epoll event (backport #21124)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When do_event_cancel() processes a pending cancellation at the top of event_fetch_inner_loop(), it removes the fd from the epoll_event_hash and calls EPOLL_CTL_DEL. However, epoll_wait() can still deliver events that were already queued in the kernel's ready list before the EPOLL_CTL_DEL took effect.
When thread_process_io_inner_loop() processes such a stale event, the hash lookup returns NULL and the assert(hash_ev) fires, crashing the daemon.
Fix:
Replace the assert with a graceful return
Crash: