Skip to content

Commit ee965fc

Browse files
committed
steamwebrtc: Add lock around cached route
This fixes race conditions between the socket thread and the GNS service thread. I believe that it is the underlying cause of #391
1 parent d7c6e44 commit ee965fc

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/external/steamwebrtc/ice_session.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class CICESession final : public IICESession, public sigslot::has_slots<>, priva
110110
EICECandidateType m_eCachedRouteLocalCandidate;
111111
EICECandidateType m_eCachedRouteRemoteCandidate;
112112
CandidateAddressString m_szCachedRouteRemoteAddress;
113+
std::mutex m_mutexCachedRoute;
113114

114115
// ICE signals
115116
void OnTransportGatheringState_n(cricket::IceTransportInternal* transport);
@@ -585,20 +586,23 @@ void CICESession::SetRemoteAuth( const char *pszUserFrag, const char *pszPwd )
585586

586587
bool CICESession::GetWritableState()
587588
{
589+
// Intentionally not taking any locks here
588590
return ice_transport_ && writable_;
589591
}
590592

591593
int CICESession::GetPing()
592594
{
595+
// Intentionally not taking any locks here
593596
if ( !ice_transport_ )
594-
m_nCachedPing = -1;
597+
return -1;
595598
return m_nCachedPing;
596599
}
597600

598601
void CICESession::CacheRouteAndPing()
599602
{
600603
AssertOnSocketThread();
601604

605+
std::lock_guard<std::mutex> lock( m_mutexCachedRoute );
602606
m_bCachedRouteValid = false;
603607
m_nCachedPing = -1;
604608
if ( !ice_transport_ )
@@ -627,6 +631,7 @@ bool CICESession::GetRoute( EICECandidateType &eLocalCandidate, EICECandidateTyp
627631
// We currently don't ever call this from the socket thread, but there's
628632
// no reason it wouldn't work, so no assert here about which thread we're on
629633

634+
std::lock_guard<std::mutex> lock( m_mutexCachedRoute );
630635
if ( !ice_transport_ )
631636
m_bCachedRouteValid = false;
632637
if ( !m_bCachedRouteValid )

0 commit comments

Comments
 (0)