Skip to content

Commit 776b08d

Browse files
authored
replay: fix hangs on exit (commaai#32795)
fix hang on exit
1 parent 77a8094 commit 776b08d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

tools/replay/camera.cc

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ CameraServer::CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS]) {
2727
CameraServer::~CameraServer() {
2828
for (auto &cam : cameras_) {
2929
if (cam.thread.joinable()) {
30+
// Clear the queue
31+
std::pair<FrameReader*, const Event *> item;
32+
while (cam.queue.try_pop(item)) {
33+
--publishing_;
34+
}
35+
36+
// Signal termination and join the thread
3037
cam.queue.push({});
3138
cam.thread.join();
3239
}

tools/replay/replay.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ Replay::~Replay() {
5050
}
5151

5252
void Replay::stop() {
53-
if (!stream_thread_ && segments_.empty()) return;
54-
55-
rInfo("shutdown: in progress...");
53+
exit_ = true;
5654
if (stream_thread_ != nullptr) {
57-
exit_ = true;
55+
rInfo("shutdown: in progress...");
5856
pauseStreamThread();
5957
stream_cv_.notify_one();
6058
stream_thread_->quit();
6159
stream_thread_->wait();
6260
stream_thread_->deleteLater();
6361
stream_thread_ = nullptr;
62+
rInfo("shutdown: done");
6463
}
6564
timeline_future.waitForFinished();
66-
rInfo("shutdown: done");
65+
camera_server_.reset(nullptr);
66+
segments_.clear();
6767
}
6868

6969
bool Replay::load() {

0 commit comments

Comments
 (0)