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

[core] fix race crash for m_RecvDataLock on shutdown #1606

Closed
wants to merge 2 commits into from

Conversation

lewk2
Copy link
Contributor

@lewk2 lewk2 commented Oct 14, 2020

We identified a problem in 1.4.2 on Windows (although likely topical on all platforms).

If a session does not establish before being stopped, then a crash can happen within the SRT library. This was identified internally as a race condition. Specifically, in the following function:

void CUDT::releaseSynch()
{
    // wake up user calls
    CSync::lock_signal(m_SendBlockCond, m_SendBlockLock);

    enterCS(m_SendLock);
    leaveCS(m_SendLock);

    CSync::lock_signal(m_RecvDataCond, m_RecvDataLock);
    CSync::lock_signal(m_RcvTsbPdCond, m_RecvLock);

    enterCS(m_RecvDataLock);
    if (m_RcvTsbPdThread.joinable())
    {
        m_RcvTsbPdThread.join();
    }
    leaveCS(m_RecvDataLock);

    enterCS(m_RecvLock);
    leaveCS(m_RecvLock);
}

Above, there is a join under m_RecvDataLock mutex, but when this thread is started in "int CUDT::processData(CUnit* in_unit)" there is no lock.

This PR adds a fix to this problem by introducing a scoped lock within the call to CUDT::processData.

This may not be the perfect way to fix -- maybe it should be another mutex dedicated for this thread. There may be other race conditions, but we think this small change should not cause terrible problems and certainly does stop crashes when a client might connect and then abort before completing a session.

It should be noted, I'm acting as somewhat of a puppet for the engineer that analyzed and patched this - so my responses might be slower than normal.

@maxsharabayko maxsharabayko added [core] Area: Changes in SRT library core Type: Bug Indicates an unexpected problem or unintended behavior labels Oct 14, 2020
@maxsharabayko maxsharabayko added this to the v1.5.0 milestone Oct 14, 2020
srtcore/core.cpp Outdated Show resolved Hide resolved
@maxsharabayko maxsharabayko self-assigned this Oct 14, 2020
Co-authored-by: Maxim Sharabayko <maxlovic@gmail.com>
@lewk2
Copy link
Contributor Author

lewk2 commented Oct 14, 2020

Please squash commits on merge so commit message can be set to proper format for release notes automation

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 Type: Bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants