@@ -5334,6 +5334,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
5334
5334
}
5335
5335
shutdown_requested_ = true ;
5336
5336
mqtt_connected_ = false ;
5337
+ async_shutdown_handler_called_ = false ;
5337
5338
5338
5339
MQTT_LOG (" mqtt_impl" , trace)
5339
5340
<< MQTT_ADD_VALUE (address, this )
@@ -5346,7 +5347,10 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
5346
5347
<< ec.message ();
5347
5348
tim_shutdown_.cancel ();
5348
5349
connected_ = false ;
5349
- if (func) func (boost::system::errc::make_error_code (boost::system ::errc::success));
5350
+ if (!async_shutdown_handler_called_) {
5351
+ async_shutdown_handler_called_ = true ;
5352
+ if (func) func (boost::system::errc::make_error_code (boost::system ::errc::success));
5353
+ }
5350
5354
}
5351
5355
);
5352
5356
// timeout timer set
@@ -5371,14 +5375,15 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
5371
5375
<< " post force_shutdown_and_close" ;
5372
5376
sp->socket ().post (
5373
5377
[this , func = force_move (func), sp] {
5374
- if (connected_ ) {
5378
+ if (!async_shutdown_handler_called_ ) {
5375
5379
error_code ec;
5376
5380
socket ().force_shutdown_and_close (ec);
5377
5381
MQTT_LOG (" mqtt_impl" , trace)
5378
5382
<< MQTT_ADD_VALUE (address, this )
5379
5383
<< " force_shutdown_and_close ec:"
5380
5384
<< ec.message ();
5381
5385
connected_ = false ;
5386
+ async_shutdown_handler_called_ = true ;
5382
5387
if (func) func (boost::system::errc::make_error_code (boost::system ::errc::success));
5383
5388
}
5384
5389
}
@@ -11591,6 +11596,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
11591
11596
std::atomic<bool > connected_{false };
11592
11597
std::atomic<bool > mqtt_connected_{false };
11593
11598
std::atomic<bool > shutdown_requested_{false };
11599
+ std::atomic<bool > async_shutdown_handler_called_{false };
11594
11600
11595
11601
std::string client_id_;
11596
11602
0 commit comments