Skip to content

Commit c43c973

Browse files
committed
join threads in close
1 parent 2fd5c29 commit c43c973

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/viam/sdk/robot/client.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,14 @@ RobotClient::~RobotClient() {
129129

130130
void RobotClient::close() {
131131
should_refresh_.store(false);
132+
133+
for (auto& thread : threads_) {
134+
thread.join();
135+
}
132136
threads_.clear();
137+
133138
stop_all();
139+
134140
viam_channel_.close();
135141
}
136142

@@ -289,13 +295,8 @@ std::shared_ptr<RobotClient> RobotClient::with_channel(ViamChannel channel,
289295
robot->refresh_interval_ = options.refresh_interval();
290296
robot->should_refresh_ = (robot->refresh_interval_ > 0);
291297
if (robot->should_refresh_) {
292-
auto t = std::thread(&RobotClient::refresh_every, robot);
293-
// TODO(RSDK-1743): this was leaking, confirm that adding thread catching in
294-
// close/destructor lets us shutdown gracefully. See also address sanitizer,
295-
// UB sanitizer
296-
t.detach();
297-
robot->threads_.push_back(std::move(t));
298-
};
298+
robot->threads_.emplace_back(&RobotClient::refresh_every, robot);
299+
}
299300

300301
robot->refresh();
301302
return robot;

0 commit comments

Comments
 (0)