From 5bb86f8bc7434048ab2d5ce0243a97d9848b34de Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 17 Dec 2024 15:11:27 -0600 Subject: [PATCH] VisionIpc: fix exception if server is killed while client is getting streams (#638) * Update visionipc_client.cc * and here in some cases * lines --- msgq/visionipc/visionipc_client.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/msgq/visionipc/visionipc_client.cc b/msgq/visionipc/visionipc_client.cc index 5e55a2d9..ac6f06ee 100644 --- a/msgq/visionipc/visionipc_client.cc +++ b/msgq/visionipc/visionipc_client.cc @@ -54,6 +54,12 @@ bool VisionIpcClient::connect(bool blocking){ int fds[VISIONIPC_MAX_FDS]; VisionBuf bufs[VISIONIPC_MAX_FDS]; r = ipc_sendrecv_with_fds(false, socket_fd, &bufs, sizeof(bufs), fds, VISIONIPC_MAX_FDS, &num_buffers); + if (r < 0) { + // only expected error is server shutting down + assert(errno == ECONNRESET); + close(socket_fd); + return false; + } assert(num_buffers >= 0); assert(r == sizeof(VisionBuf) * num_buffers); @@ -122,7 +128,14 @@ std::set VisionIpcClient::getAvailableStreams(const std::strin VisionStreamType available_streams[VISION_STREAM_MAX] = {}; r = ipc_sendrecv_with_fds(false, socket_fd, &available_streams, sizeof(available_streams), nullptr, 0, nullptr); - assert((r >= 0) && (r % sizeof(VisionStreamType) == 0)); + if (r < 0) { + // only expected error is server shutting down + assert(errno == ECONNRESET); + close(socket_fd); + return {}; + } + + assert(r % sizeof(VisionStreamType) == 0); close(socket_fd); return std::set(available_streams, available_streams + r / sizeof(VisionStreamType)); }