Skip to content

fix: occasional deadlock configuring AVCaptureSession - WPB-23237#4259

Merged
samwyndham merged 2 commits intorelease/cycle-4.15from
fix/crash-starting-camera-preview-WPB-23237
Feb 5, 2026
Merged

fix: occasional deadlock configuring AVCaptureSession - WPB-23237#4259
samwyndham merged 2 commits intorelease/cycle-4.15from
fix/crash-starting-camera-preview-WPB-23237

Conversation

@samwyndham
Copy link
Contributor

@samwyndham samwyndham commented Feb 3, 2026

BugWPB-23237 [iOS] Replicated Once - Screen freeze and Crash observed on camera permission

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 beginConfiguration on the AVCaptureSession from two threads (main + background) and that there is a deadlock before any call to commitConfiguration. Debugging I found that the main thread call happens internally when instantiating AVCaptureVideoPreviewLayer.

My fix is to first instantiate AVCaptureVideoPreviewLayer before doing our own background thread configuration of AVCaptureSession. I have observed this leads to the AVCaptureVideoPreviewLayer completing it's configuration of the session before we do it.

Testing

  1. Navigate to a conversation
  2. Repeatably tap the camera button so the camera input shows and hides
  3. Continue for a few minutes
  4. The UI should not freeze.

Checklist

  • Title contains a reference JIRA issue number like [WPB-XXX].
  • Description is filled and free of optional paragraphs.
  • Adds/updates automated tests.

UI accessibility checklist

If your PR includes UI changes, please utilize this checklist:

  • Make sure you use the API for UI elements that support large fonts.
  • All colors are taken from WireDesign.ColorTheme or constructed using WireDesign.BaseColorPalette.
  • New UI elements have Accessibility strings for VoiceOver.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 after previewLayer initialization 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.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Test Results

1 867 tests   1 840 ✅  2m 4s ⏱️
  301 suites     27 💤
    1 files        0 ❌

Results for commit 6b6699b.

♻️ This comment has been updated with latest results.

Summary: workflow run #21716416093
Allure report (download zip): html-report-27579-fix_crash-starting-camera-preview-WPB-23237

@samwyndham samwyndham force-pushed the fix/crash-starting-camera-preview-WPB-23237 branch from b49a39a to e932eac Compare February 4, 2026 13:10
@samwyndham samwyndham changed the base branch from develop to release/cycle-4.15 February 4, 2026 13:10
Copy link
Collaborator

@netbe netbe left a comment

Choose a reason for hiding this comment

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

LGTM;)

@samwyndham samwyndham merged commit 4dc0675 into release/cycle-4.15 Feb 5, 2026
10 checks passed
@samwyndham samwyndham deleted the fix/crash-starting-camera-preview-WPB-23237 branch February 5, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants