Skip to content

Keep the ASWebAuthenticationSession alive until its dismissal finishes - #985

Open
w-goog wants to merge 3 commits into
masterfrom
fix/917-session-retain
Open

w-goog wants to merge 3 commits into
masterfrom
fix/917-session-retain

Conversation

@w-goog

@w-goog w-goog commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

(Fresh-branch version of #917 by @Prash88)

On cancel, ASWebAuthenticationSession's completion handler runs before its dismiss transition starts (this is an apple bug, radar is linked at the end). We dropped our last reference inside that handler, so the transition's completion block later released an already-freed SFAuthenticationSession - EXC_BAD_ACCESS once the sheet finished animating.

At each release point the session goes to a main-queue block that holds it for one turn + 2s. The delay starts once the main queue is next free, so a slow completion callback doesn't eat into it (2s is a guess, there's no real API to observe the transition).

I also tried the messy option of inspecting the transitionCoordinator to time against the animation, but the crash happened before that was available.

Not covered here: the Catalyst agent has the same handler pattern. There's no unit test, as dealloc timing isn't unit-testable.

Verified on the iOS 26.4 simulator: 3 cancels via the #917 repro, no crash.

Radar link: https://openradar.appspot.com/FB12132525
Dev forum workaround link: https://developer.apple.com/forums/thread/123667

Note to reviewer: Sent you some additional internal context on chat.

@w-goog
w-goog requested a review from camden-king October 21, 2026 22:18

This branch has not been deployed

No deployments
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.

2 participants