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

Close interceptor after PeerConnection is closed #2977

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

aalekseevx
Copy link
Member

The following panic was encountered in the stats interceptor:

panic: sync: WaitGroup is reused before previous Wait has returned

sync.(*WaitGroup).Wait(0xc08227bce0?)
go/_std_1.22/src/sync/waitgroup.go:118 +0x74
github.com/pion/interceptor/pkg/stats.(*Interceptor).Close(0xc08ff1de20?)
github.com/pion/interceptor.(*Chain).Close(0xc0423bbb90?)
github.com/pion/webrtc/v4.(*PeerConnection).close(0xc0423bbb80, 0x0)
github.com/pion/webrtc/v4.(*PeerConnection).Close(...)
github.com/pion/webrtc/v4.(*PeerConnection).startTransports.func1.1()

It occurs because wg.Add is called after wg.Wait. This implies that Bind was called after the interceptor had already been closed, which appears to be incorrect.

I was able to reproduce this issue in tests, but the reproduction is highly flaky (it might only work on my machine with the provided constants) and takes a long time to run. As a result, it doesn't seem practical to include it as a test case:

https://gist.github.com/aalekseevx/5b31eed4fe3e524502217cc02273345e

The proposed solution is to ensure that interceptor.close() is called only after the peer connection is fully closed—whether in a graceful or non-graceful manner—so that no track can be added afterward.

@aalekseevx aalekseevx requested a review from Sean-Der December 24, 2024 12:54
Copy link

codecov bot commented Dec 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.91%. Comparing base (b82306a) to head (f36bb3d).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2977      +/-   ##
==========================================
+ Coverage   77.82%   77.91%   +0.08%     
==========================================
  Files          89       89              
  Lines       10523    10524       +1     
==========================================
+ Hits         8190     8200      +10     
+ Misses       1843     1836       -7     
+ Partials      490      488       -2     
Flag Coverage Δ
go 79.49% <100.00%> (+0.09%) ⬆️
wasm 63.45% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aalekseevx
Copy link
Member Author

Investigating the broken CI

@aalekseevx aalekseevx force-pushed the fix-interceptor-close-race branch 2 times, most recently from 94d8b56 to 114d37f Compare December 24, 2024 13:24
Copy link
Member

@Sean-Der Sean-Der left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Thank you @aalekseevx

@aalekseevx aalekseevx force-pushed the fix-interceptor-close-race branch from 5eed59c to f36bb3d Compare December 24, 2024 20:08
@aalekseevx aalekseevx merged commit 3f246fd into pion:master Dec 24, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants