fix: occasional deadlock configuring AVCaptureSession - WPB-23237#4259
Merged
samwyndham merged 2 commits intorelease/cycle-4.15from Feb 5, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an occasional deadlock issue (WPB-23237) that occurs when repeatedly showing and hiding the camera input by reordering the initialization sequence in CameraController. The deadlock was caused by concurrent configuration of the AVCaptureSession from multiple threads.
Changes:
- Moved the
setupSession()call to occur afterpreviewLayerinitialization to prevent concurrent session configuration - Added detailed inline documentation explaining the threading implications and rationale for the ordering
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Test Results1 867 tests 1 840 ✅ 2m 4s ⏱️ Results for commit 6b6699b. ♻️ This comment has been updated with latest results. Summary: workflow run #21716416093 |
b49a39a to
e932eac
Compare
David-Henner
approved these changes
Feb 5, 2026
zenkins
pushed a commit
that referenced
this pull request
Feb 5, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Sometimes when the camera button is tapped and the preview loads we get a deadlock. I've managed to reproduce this a few times by showing and hiding the camera input repeatably but it can take time to happen. @findms originally found the issue after giving phone permissions.
Looking at the crash report in the jira ticket we see that we have called
beginConfigurationon theAVCaptureSessionfrom two threads (main + background) and that there is a deadlock before any call tocommitConfiguration. Debugging I found that the main thread call happens internally when instantiatingAVCaptureVideoPreviewLayer.My fix is to first instantiate
AVCaptureVideoPreviewLayerbefore doing our own background thread configuration ofAVCaptureSession. I have observed this leads to theAVCaptureVideoPreviewLayercompleting it's configuration of the session before we do it.Testing
Checklist
[WPB-XXX].UI accessibility checklist
If your PR includes UI changes, please utilize this checklist: