api: avoid sigpipe for unruly api client 56/37756/4
authorOle Troan <ot@cisco.com>
Tue, 6 Dec 2022 16:07:39 +0000 (17:07 +0100)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 7 Dec 2022 10:33:07 +0000 (10:33 +0000)
if the api client didn't wait for the last message, we'd get a SIGPIPE
from Unix and VPP would crash.

Type: fix
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Iac7705ec09ccd67cc249cc9a9525a7cb379e2f6f
Signed-off-by: Ole Troan <ot@cisco.com>
src/vlibmemory/socket_api.c

index 6559f73..24a4609 100644 (file)
@@ -220,6 +220,12 @@ static void
 socket_cleanup_pending_remove_registration_cb (u32 *preg_index)
 {
   vl_api_registration_t *rp = vl_socket_get_registration (*preg_index);
+  if (!rp)
+    {
+      /* Might already have gone */
+      return;
+    }
+
   clib_file_main_t *fm = &file_main;
   u32 pending_remove_file_index = vl_api_registration_file_index (rp);
 
@@ -402,7 +408,7 @@ vl_socket_write_ready (clib_file_t * uf)
   while (remaining_bytes > 0)
     {
       bytes_to_send = remaining_bytes > 4096 ? 4096 : remaining_bytes;
-      n = write (uf->file_descriptor, p, bytes_to_send);
+      n = send (uf->file_descriptor, p, bytes_to_send, MSG_NOSIGNAL);
       if (n < 0)
        {
          if (errno == EAGAIN)