]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: don't close client socket from I/O pthread
authorQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 1 Aug 2018 19:27:13 +0000 (19:27 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 1 Aug 2018 19:41:47 +0000 (19:41 +0000)
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 <qlyoung@cumulusnetworks.com>
zebra/zserv.c

index 4960ba03a60ca1a31a7401dac6422c1e7970d19a..f76c2fabd63412defcd8c0ce735667c86fb521db 100644 (file)
@@ -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);