fix: prevent deadlock when sending photo from camera to new contact (…#14679
Closed
benny10ben wants to merge 1 commit intosignalapp:mainfrom
Closed
fix: prevent deadlock when sending photo from camera to new contact (…#14679benny10ben wants to merge 1 commit intosignalapp:mainfrom
benny10ben wants to merge 1 commit intosignalapp:mainfrom
Conversation
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.
Fixes #14674
First time contributor checklist
Contributor checklist
Fixes #1234syntaxDescription
Problem
When opening the in-app camera from the chat list (not from inside a conversation),
taking a photo, and sending it to a contact, a permanent deadlock occurs. A spinning
indicator appears over the image and never resolves. Backing out and relaunching the
app leaves it in a broken state where messages cannot be sent until the app is
force-stopped or the device is rebooted.
Reported log line:
Root cause
When the camera is launched from the chat list,
destinationis set toChooseAfterMediaSelection— meaning no recipient is known yet. However,shouldPreUpload()only checked network metering, so on a Wi-Fi connectionisPreUploadEnabledwas set totrueeven with a null recipient.This caused
startUpload(media, null)to fire immediately after the photo wastaken, spawning a background thread (Thread A) that inserted attachment rows into
SQLite and held a write lock.
When the user later picked a contact and hit send,
repository.send()calleduploadRepository.applyMediaUpdates(null)on a second thread (Thread B), whichneeded the same write lock. Thread B blocked waiting on Thread A, Thread A stalled
waiting on Thread B's downstream work, and neither thread ever completed.
Fix
Added a single guard to
shouldPreUpload()inMediaSelectionViewModel:isContactSelectionRequiredis already computed fromdestinationat init time andexactly captures the "recipient not yet known" state. Setting
isPreUploadEnabledto
falsein this case prevents the upload thread from spawning at all, eliminatingthe lock contention entirely.
All other entry points (inside-chat camera, gallery, editor, share, stories) pass a
concrete destination with a known recipient, so
isContactSelectionRequiredisfalsefor all of them — their behaviour is completely unchanged.Testing
Reproduced the deadlock on Samsung Galaxy S23 / Android 16 following the exact steps
in issue #14674. Confirmed the fix resolves it. Also verified on Android Emulator
Pixel 9 / Android 16 that the inside-chat camera flow, gallery send, and share flow
all continue to work correctly with pre-upload enabled as before.