Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Potential leak of TSBPD thread #1624

Closed
maxsharabayko opened this issue Oct 23, 2020 · 0 comments · Fixed by #1629
Closed

[BUG] Potential leak of TSBPD thread #1624

maxsharabayko opened this issue Oct 23, 2020 · 0 comments · Fixed by #1629
Assignees
Labels
[core] Area: Changes in SRT library core Priority: High Type: Bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@maxsharabayko
Copy link
Collaborator

The join() operation on the TSBPD thread may be missed if CUDT::releaseSynch() finishes its execution while the receiving thread is still active and is only about to create this thread (see StartThread(m_RcvTsbPdThread, CUDT::tsbpd, ...) in CUDT::processData(..))..

It can only happen if a socket was closed right before the very first DATA packet has arrived.
The issue does not happen if the reception has already started.

This issue was reported through #1606.

The potential TSBPD thread leak existed in previous versions as well and is not something introduced in v1.4.2.
However, only C++11 threads throw an exception from the destructor if the thread is still joinable (see ~thread()).

On Windows:

  • When C++11 threads are used, the std::thread's destructor throws an exception if the thread is still joinable (no one waited for it to complete).
  • When pthread wrapping library is used, no exception is thrown. Hopefully, the leaking thread is then cleaned up by pthread's garbage collector.

On Linux:

  • Using C++11 thread throws an exception if thread leaked (-DENABLE_STDCXX_SYNC=ON).
  • Using pthreads does not throw an exception (-DENABLE_STDCXX_SYNC=OFF).
void CUDT::releaseSynch()
{
    // ...

    enterCS(m_RecvDataLock);
    if (m_RcvTsbPdThread.joinable())
    {
        m_RcvTsbPdThread.join();
    }
    leaveCS(m_RecvDataLock);
    // ...
}
@maxsharabayko maxsharabayko added Priority: High Type: Bug Indicates an unexpected problem or unintended behavior [core] Area: Changes in SRT library core labels Oct 23, 2020
@maxsharabayko maxsharabayko added this to the v1.4.3 milestone Oct 23, 2020
@maxsharabayko maxsharabayko self-assigned this Oct 23, 2020
@maxsharabayko maxsharabayko linked a pull request Oct 23, 2020 that will close this issue
1 task
maxsharabayko added a commit to maxsharabayko/srt that referenced this issue Oct 29, 2020
maxsharabayko added a commit to maxsharabayko/srt that referenced this issue Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[core] Area: Changes in SRT library core Priority: High Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
1 participant