Skip to content

Fix a deadlock in TaskLoop - #840

Merged
JoTurk merged 1 commit into
masterfrom
fix-deadlock
Nov 26, 2025
Merged

JoTurk merged 1 commit into
masterfrom
fix-deadlock

Conversation

@JoTurk

@JoTurk JoTurk commented Nov 26, 2025 •

Copy link
Copy Markdown
Member

Description

Fixes a rare race condition in taskloop if close fired just while Run was getting called in the tiny window after the err check and just before Run gets called, and because the context is actually set to the loop itself we get a deadlock.

Reference issue

I saw it happening this week and I think it Fixes pion/interceptor#384 but not 100% sure

@codecov

codecov Bot commented Nov 26, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.30%. Comparing base (30c406b) to head (4537cf7).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #840      +/-   ##
==========================================
+ Coverage   87.15%   87.30%   +0.15%     
==========================================
  Files          43       43              
  Lines        4819     4821       +2     
==========================================
+ Hits         4200     4209       +9     
+ Misses        445      438       -7     
  Partials      174      174              
Flag Coverage Δ
go 87.30% <100.00%> (+0.15%) ⬆️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread internal/taskloop/taskloop_test.go Resolved

@philipch07 philipch07 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, I meant to approve + ask the question. The test looks fine; the question is just about a possible enhancement but isn't make-or-break^

@JoTurk
JoTurk merged commit 4537cf7 into master Nov 26, 2025
@JoTurk
JoTurk deleted the fix-deadlock branch November 26, 2025 18:44
boks1971 added a commit to livekit/livekit that referenced this pull request Nov 27, 2025
After adding more fields in
https://github.com/livekit/livekit/pull/4105/files, it was not even
logging. Access to one of the added fields must have ended up waiting on
a lock and blocked.

Unfotunately, the deadlock fix in pion/ice#840
did not address the peer connection close hang.

Splitting the logs so that the base log still happens. Ordering after
looking at the code and guessing what could still log to see if we get
more of the logs and learn more about the state and which lock ends up
the first blocking one.
boks1971 added a commit to livekit/livekit that referenced this pull request Nov 27, 2025
After adding more fields in
https://github.com/livekit/livekit/pull/4105/files, it was not even
logging. Access to one of the added fields must have ended up waiting on
a lock and blocked.

Unfotunately, the deadlock fix in pion/ice#840
did not address the peer connection close hang.

Splitting the logs so that the base log still happens. Ordering after
looking at the code and guessing what could still log to see if we get
more of the logs and learn more about the state and which lock ends up
the first blocking one.
zeekay pushed a commit to hanzoai/livekit that referenced this pull request Sep 9, 2026
After adding more fields in
https://github.com/livekit/livekit/pull/4105/files, it was not even
logging. Access to one of the added fields must have ended up waiting on
a lock and blocked.

Unfotunately, the deadlock fix in pion/ice#840
did not address the peer connection close hang.

Splitting the logs so that the base log still happens. Ordering after
looking at the code and guessing what could still log to see if we get
more of the logs and learn more about the state and which lock ends up
the first blocking one.
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.

Interceptor.loop() goroutine leak

3 participants