Skip to content

Commit 70bba0b

Browse files
committed
Fix tls socket can block on clean shutdown
1 parent 62a16b2 commit 70bba0b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

include/mqtt/endpoint.hpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
11001100
<< MQTT_ADD_VALUE(address, this)
11011101
<< "force_disconnect";
11021102

1103-
sync_shutdown(socket());
1103+
sync_force_shutdown(socket());
11041104
}
11051105

11061106
/**
@@ -5326,6 +5326,31 @@ class endpoint : public std::enable_shared_from_this<endpoint<Mutex, LockGuard,
53265326
connected_ = false;
53275327
}
53285328

5329+
void sync_force_shutdown(MQTT_NS::socket& s) {
5330+
MQTT_LOG("mqtt_impl", trace)
5331+
<< MQTT_ADD_VALUE(address, this)
5332+
<< "sync_force_shutdown";
5333+
if (shutdown_requested_) {
5334+
MQTT_LOG("mqtt_impl", trace)
5335+
<< MQTT_ADD_VALUE(address, this)
5336+
<< "already shutdowned";
5337+
return;
5338+
}
5339+
shutdown_requested_ = true;
5340+
mqtt_connected_ = false;
5341+
5342+
error_code ec;
5343+
MQTT_LOG("mqtt_impl", trace)
5344+
<< MQTT_ADD_VALUE(address, this)
5345+
<< "force_shutdown_and_close";
5346+
s.force_shutdown_and_close(ec);
5347+
MQTT_LOG("mqtt_impl", trace)
5348+
<< MQTT_ADD_VALUE(address, this)
5349+
<< "force_shutdown_and_close ec:"
5350+
<< ec.message();
5351+
connected_ = false;
5352+
}
5353+
53295354
void async_shutdown(MQTT_NS::socket& s, async_handler_t func) {
53305355
MQTT_LOG("mqtt_impl", trace)
53315356
<< MQTT_ADD_VALUE(address, this)

0 commit comments

Comments
 (0)