From c022637847cffee5444f893a26dcca0ac6873e54 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 1 Aug 2018 19:27:13 +0000 Subject: [PATCH] zebra: don't close client socket from I/O pthread The client socket value can only be modified by the main thread. Modifying the client socket from within the client I/O pthread introduces race conditions. Signed-off-by: Quentin Young --- zebra/zserv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/zebra/zserv.c b/zebra/zserv.c index 4960ba03a6..f76c2fabd6 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -163,6 +163,9 @@ static void zserv_log_message(const char *errmsg, struct stream *msg, * Cancel any pending tasks for the client's thread. Then schedule a task on * the main thread to shut down the calling thread. * + * It is not safe to close the client socket in this function. The socket is + * owned by the main thread. + * * Must be called from the client pthread, never the main thread. */ static void zserv_client_fail(struct zserv *client) @@ -172,10 +175,7 @@ static void zserv_client_fail(struct zserv *client) atomic_store_explicit(&client->pthread->running, false, memory_order_relaxed); - if (client->sock > 0) { - close(client->sock); - client->sock = -1; - } + THREAD_OFF(client->t_read); THREAD_OFF(client->t_write); zserv_event(client, ZSERV_HANDLE_CLIENT_FAIL); -- 2.39.5