Resolve room handle synchronously in on_disconnect#1066
Draft
MaxHeimbrock wants to merge 1 commit intomainfrom
Draft
Resolve room handle synchronously in on_disconnect#1066MaxHeimbrock wants to merge 1 commit intomainfrom
MaxHeimbrock wants to merge 1 commit intomainfrom
Conversation
The handler spawned an async task that retrieved the FfiRoom via the DashMap inside the spawn body and unwrap()'d the result. The synchronous DisconnectResponse returned to the foreign-language client before the spawn was scheduled, so a client that disposed its room handle as soon as the request returned would race the tokio scheduler. When the spawn finally polled, retrieve_handle saw the entry already removed by drop_handle and the unwrap aborted the process via SIGABRT inside the runtime worker. On iOS the race lost roughly half the time. Move the retrieve_handle + clone before the spawn. The spawn now owns its Arc<FfiRoom> clone, so the close runs even if the foreign side has already removed the DashMap entry. Also replace the unwrap with `?` so a genuinely missing handle surfaces as a proper FfiResult error rather than an abort. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
No changeset foundThis PR modifies the following packages but doesn't include a changeset: Directly changed:
Click here to create a changeset The link pre-populates a changeset file with If this change doesn't require a version bump, add the |
Contributor
Author
|
Would the fix in max/fix-on-disconnect-handle-race not be needed if we dispose the room only after the disconnect event arrives back in Unity? |
3 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.
Summary
on_disconnectspawned an async task that retrieved theFfiRoomvia the DashMap inside the spawn body andunwrap()'d the result. The synchronousDisconnectResponsereturned to the foreign-language client before the spawn was scheduled, so a client that disposed its room handle as soon as the request returned would race the tokio scheduler. When the spawn finally polled,retrieve_handlesaw the entry already removed bydrop_handleand the unwrap aborted the process viaSIGABRTinside the runtime worker. On iOS the race lost roughly half the time.Move the
retrieve_handle + clonebefore the spawn. The spawn now owns itsArc<FfiRoom>clone, so the close runs even if the foreign side has already removed the DashMap entry. Also replace theunwrapwith?so a genuinely missing handle surfaces as a properFfiResulterror rather than an abort.Surfaced in the Unity SDK after a separate change started disposing the room handle synchronously on disconnect (rather than waiting for the
Disconnectedevent + GC of the SafeHandle). Either change is reasonable on the foreign side; the FFI server should be robust to it.Test plan
🤖 Generated with Claude Code