Skip to content
This repository has been archived by the owner on Jun 1, 2021. It is now read-only.

Commit

Permalink
close channel only after queues have stopped their workers, fixes bar…
Browse files Browse the repository at this point in the history
…chart#83

Otherwise, the socket is closed and the file descriptor is freed prematurely.
Due to a race condition the queues might then still be trying to use the old
file descriptor which by now may already point to another unrelated socket. This
may either lead to "stolen" data, data that is read accidentally by the
queue worker for the already closed socket. Or it may lead to a complete deadlock,
if the file descriptor now points to a blocking socket, so that
`delete m->second.m_pRcvQueue` will never return because it joins the worker
thread which blocks indefinitely on the wrong socket. After some time this
deadlock will bring UDT completely to a halt because the above code holds the
m_ControlLock into which all other work will run and block there after a while.

(cherry picked from commit ccb843e)
  • Loading branch information
jrudolph committed Jun 1, 2016
1 parent 4ada186 commit 5a031f3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion barchart-udt-core/src/main/c++/udt/src/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,10 +1305,10 @@ void CUDTUnited::removeSocket(const UDTSOCKET u)
m->second.m_iRefCount --;
if (0 == m->second.m_iRefCount)
{
m->second.m_pChannel->close();
delete m->second.m_pSndQueue;
delete m->second.m_pRcvQueue;
delete m->second.m_pTimer;
m->second.m_pChannel->close();
delete m->second.m_pChannel;
m_mMultiplexer.erase(m);
}
Expand Down

0 comments on commit 5a031f3

Please sign in to comment.