Commit 5f134a2b08 for frr
commit 5f134a2b086d39d6bc3ab5e59205cfe83c86bb31
Author: Nick Bouliane <nbouliane@coreweave.com>
Date: Mon Nov 30 06:19:33 2026 -0500
zebra: cancel the zapi accept event when the listener socket is closed
zserv_close() closes the listener socket of the zapi server, but the
read event that waits for connections on it stays registered in the
event loop. It is added without a reference, so nothing can cancel it.
zebra does not exit right after zserv_close(). sigint() returns to the
event loop, which runs until the dataplane is done removing the routes,
and the vty server still accepts connections during that time. A file
descriptor that is opened then can get the number that the listener
socket had. When it is a vtysh connection, vtysh_accept() adds a read
event for a file descriptor that the event loop already has a read
event for, and a build with --enable-dev-build, which is what the
topotests run, aborts:
ZEBRA: lib/event.c:1391: _event_add_read_write(): assertion
(!"Thread already scheduled for file descriptor") failed
Without --enable-dev-build the assert is not compiled. The new event
replaces the event of zserv_accept() in the read array of the event
loop, and the replaced event is never freed.
This was found on 10.7.1, which has the same zserv.c, where zebra
dumped core 3 times while FRR was being stopped in a test topology.
To reproduce it, start zebra alone, run "vtysh -d zebra -c 'show
version'" in a loop and send SIGINT to zebra. zebra aborted in 17
stops out of 300, and in none out of 300 with this change.
Keep a reference to the accept event in zrouter, and cancel it before
the socket is closed.
Fixes: 416745628e ("zebra: When shutting down actually close the socket")
Signed-off-by: Nick Bouliane <nbouliane@coreweave.com>
diff --git a/zebra/zebra_router.h b/zebra/zebra_router.h
index 85bedca434..6c9676eaaf 100644
--- a/zebra/zebra_router.h
+++ b/zebra/zebra_router.h
@@ -147,6 +147,9 @@ struct zebra_router {
/* Wheel to process V6 RA update */
struct timer_wheel *ra_wheel;
+ /* The event that accepts the connections on the zapi listener socket */
+ struct event *t_zserv_accept;
+
/* Lists of clients who have connected to us */
struct zserv_client_list_head client_list;
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 3659bbf9e5..3750ea7b13 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -953,6 +953,7 @@ void zserv_close(void)
* routing table doesn't leave us in a bad
* state where a client tries to reconnect
*/
+ event_cancel(&zrouter.t_zserv_accept);
close(zsock);
zsock = -1;
@@ -1055,7 +1056,7 @@ void zserv_event(struct zserv *client, enum zserv_event event)
{
switch (event) {
case ZSERV_ACCEPT:
- event_add_read(zrouter.master, zserv_accept, NULL, zsock, NULL);
+ event_add_read(zrouter.master, zserv_accept, NULL, zsock, &zrouter.t_zserv_accept);
break;
case ZSERV_PROCESS_MESSAGES:
event_add_event(zrouter.master, zserv_process_messages, client,