From: Stanislav Zaikin Date: Fri, 1 Nov 2024 11:57:27 +0000 (+0100) Subject: vapi: connect/disconnect error handling uds transport X-Git-Tag: v25.10-rc0~45 X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F08%2F42208%2F2;p=vpp.git vapi: connect/disconnect error handling uds transport A sudden vpp restart can put vapi into weird state when it tries to read from closed socket. Fix that by checking for EOF and add some more error handling to connect and disconnect. Type: fix Change-Id: Ida4e69f839e6bfcc470a8a74899975263735d0c0 Signed-off-by: Stanislav Zaikin --- diff --git a/src/vpp-api/vapi/vapi.c b/src/vpp-api/vapi/vapi.c index 9e5101bd9f9..e9fd346fbbb 100644 --- a/src/vpp-api/vapi/vapi.c +++ b/src/vpp-api/vapi/vapi.c @@ -507,6 +507,10 @@ vapi_sock_recv_internal (vapi_ctx_t ctx, u8 **vec_msg, u32 timeout) vec_validate (sock->rx_buffer, sizeof (*mbp) - 1); n = recv (sock->fd, sock->rx_buffer + current_rx_index, sizeof (*mbp) - current_rx_index, MSG_DONTWAIT); + + if (n == 0) + return VAPI_ECONNRESET; + if (n < 0) { if (errno == EAGAIN && clib_time_now (&ctx->time) >= deadline) @@ -776,15 +780,19 @@ vapi_sock_client_connect (vapi_ctx_t ctx, char *path, const char *name) { qstatus = vapi_sock_recv_internal (ctx, &msg, 0); - if (qstatus == 0) + if (qstatus == VAPI_OK) goto read_one_msg; + + if (qstatus != VAPI_EAGAIN) + return VAPI_ECON_FAIL; + ts.tv_sec = 0; ts.tv_nsec = 10000 * 1000; /* 10 ms */ while (nanosleep (&ts, &tsrem) < 0) ts = tsrem; } /* Timeout... */ - return -1; + return VAPI_ECON_FAIL; read_one_msg: if (vec_len (msg) == 0) @@ -1338,9 +1346,14 @@ vapi_sock_disconnect (vapi_ctx_t ctx) rv = VAPI_ENORESP; goto fail; } - if (vapi_sock_recv_internal (ctx, &msg, 0) < 0) + + rv = vapi_sock_recv_internal (ctx, &msg, 0); + if (rv == VAPI_EAGAIN) continue; + if (rv != VAPI_OK) + goto fail; + if (vec_len (msg) == 0) continue;