@@ -116,12 +116,14 @@ void RobotClient::connect_logging() {
116116}
117117
118118RobotClient::~RobotClient () {
119- try {
120- this ->close ();
121- } catch (const std::exception& e) {
122- VIAM_SDK_LOG (error) << " Received err while closing RobotClient: " << e.what ();
123- } catch (...) {
124- VIAM_SDK_LOG (error) << " Received unknown err while closing RobotClient" ;
119+ if (should_close_channel_) {
120+ try {
121+ this ->close ();
122+ } catch (const std::exception& e) {
123+ VIAM_SDK_LOG (error) << " Received err while closing RobotClient: " << e.what ();
124+ } catch (...) {
125+ VIAM_SDK_LOG (error) << " Received unknown err while closing RobotClient" ;
126+ }
125127 }
126128}
127129
@@ -254,6 +256,7 @@ void RobotClient::refresh_every() {
254256
255257RobotClient::RobotClient (ViamChannel channel)
256258 : viam_channel_(std::move(channel)),
259+ should_close_channel_ (false ),
257260 impl_(std::make_unique<impl>(RobotService::NewStub(viam_channel_.channel()))) {}
258261
259262std::vector<Name> RobotClient::resource_names () const {
@@ -304,6 +307,7 @@ std::shared_ptr<RobotClient> RobotClient::at_address(const std::string& address,
304307 const char * uri = address.c_str ();
305308 auto robot =
306309 RobotClient::with_channel (ViamChannel::dial_initial (uri, options.dial_options ()), options);
310+ robot->should_close_channel_ = true ;
307311
308312 return robot;
309313};
@@ -314,6 +318,7 @@ std::shared_ptr<RobotClient> RobotClient::at_local_socket(const std::string& add
314318 auto robot = RobotClient::with_channel (
315319 ViamChannel (sdk::impl::create_viam_channel (addr, grpc::InsecureChannelCredentials ())),
316320 options);
321+ robot->should_close_channel_ = true ;
317322
318323 return robot;
319324};
0 commit comments