Skip to content

Commit

Permalink
Safely release SIP user agent semaphore (#984)
Browse files Browse the repository at this point in the history
  • Loading branch information
SipSorceryFan authored Oct 2, 2023
1 parent ec8fed0 commit 2566204
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/app/SIPUserAgents/SIPUserAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ public async Task<bool> Answer(SIPServerUserAgent uas, IMediaSession mediaSessio
}
finally
{
m_semaphoreSlim.Release();
TryReleaseSemaphore();
}
}

Expand Down Expand Up @@ -1753,7 +1753,7 @@ private void CallEnded(string callId)
}
finally
{
m_semaphoreSlim.Release();
TryReleaseSemaphore();
}
}

Expand Down Expand Up @@ -1940,8 +1940,20 @@ public void Dispose()

// Wait for completion of CallEnded and Answer methods
m_semaphoreSlim.Wait();
m_semaphoreSlim.Release();
TryReleaseSemaphore();
m_semaphoreSlim.Dispose();
}

private void TryReleaseSemaphore()
{
try
{
m_semaphoreSlim.Release();
}
catch (ObjectDisposedException)
{
//Swallow it
}
}
}
}

0 comments on commit 2566204

Please sign in to comment.