@@ -1262,6 +1262,8 @@ void DataSubscriber::Disconnect(const bool joinThread, const bool autoReconnecti
12621262 return ;
12631263 }
12641264
1265+ bool useConnectActionMutex = !autoReconnecting || m_listening;
1266+
12651267 // Notify running threads that the subscriber is disconnecting, i.e., disconnect thread is active
12661268 m_disconnecting = true ;
12671269 m_connected = false ;
@@ -1277,7 +1279,7 @@ void DataSubscriber::Disconnect(const bool joinThread, const bool autoReconnecti
12771279 {
12781280 ScopeLock lock (m_disconnectThreadMutex);
12791281
1280- m_disconnectThread = Thread ([this , autoReconnecting, includeListener]
1282+ m_disconnectThread = Thread ([this , autoReconnecting, includeListener, useConnectActionMutex ]
12811283 {
12821284 try
12831285 {
@@ -1286,9 +1288,11 @@ void DataSubscriber::Disconnect(const bool joinThread, const bool autoReconnecti
12861288 {
12871289 m_connector.Cancel ();
12881290 m_connectionTerminationThread.join ();
1289- m_connectActionMutex.lock ();
12901291 }
12911292
1293+ if (useConnectActionMutex)
1294+ m_connectActionMutex.lock ();
1295+
12921296 ErrorCode error;
12931297
12941298 // Release queues and close sockets so that threads can shut down gracefully
@@ -1340,10 +1344,9 @@ void DataSubscriber::Disconnect(const bool joinThread, const bool autoReconnecti
13401344 if (m_autoReconnectCallback != nullptr && !m_disposing)
13411345 m_autoReconnectCallback (this );
13421346 }
1343- else
1344- {
1347+
1348+ if (useConnectActionMutex)
13451349 m_connectActionMutex.unlock ();
1346- }
13471350 });
13481351 }
13491352
0 commit comments