Skip to content

Commit 06c072f

Browse files
STAR-1582 Fix deadlock on client stop (#32)
Fix deadlock when shutting down a client, which would get stuck indefinitly 1 out of 5 times in the main thread when calling stop. The deadlock was casued by the main thread getting stuck while waiting for the client thread to join. At the same time, the client worker thread was stuck waiting for recv to return a value. In case no data was sent on the network and the remote side did not disconnect, the main thread will be stuck indefinitly. This commit solves the issue by first closing the SRT socket before trying to join the thread, instead of after, as earlier. This makes the recv call return an error and exit the thread loop.
1 parent 0f49f18 commit 06c072f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

SRTNet.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,6 @@ bool SRTNet::stop() {
899899
} else if (mCurrentMode == Mode::client) {
900900
mClientActive = false;
901901

902-
if (mWorkerThread.joinable()) {
903-
mWorkerThread.join();
904-
}
905-
906902
std::lock_guard<std::mutex> lock(mNetMtx);
907903
if (mContext != SRT_INVALID_SOCK) {
908904
int result = srt_close(mContext);
@@ -912,6 +908,11 @@ bool SRTNet::stop() {
912908
return false;
913909
}
914910
}
911+
912+
if (mWorkerThread.joinable()) {
913+
mWorkerThread.join();
914+
}
915+
915916
mClientConnected = false;
916917

917918
SRT_LOGGER(true, LOGG_NOTIFY, "Client stopped");

0 commit comments

Comments
 (0)