Skip to content

Commit

Permalink
VisionIpc: fix exception if server is killed while client is getting …
Browse files Browse the repository at this point in the history
…streams (commaai#638)

* Update visionipc_client.cc

* and here in some cases

* lines
  • Loading branch information
sshane authored Dec 17, 2024
1 parent 434ed23 commit 5bb86f8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion msgq/visionipc/visionipc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -122,7 +128,14 @@ std::set<VisionStreamType> 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<VisionStreamType>(available_streams, available_streams + r / sizeof(VisionStreamType));
}
Expand Down

0 comments on commit 5bb86f8

Please sign in to comment.