Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Web Auth race condition [SDK-3522] #731

Merged
merged 6 commits into from
Jul 29, 2022

Conversation

Widcket
Copy link
Contributor

@Widcket Widcket commented Jul 28, 2022

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

This PR fixes a race condition in Web Auth code that lead to a crash when using Auth0.swift with async/await. In particular, the crash happens when the login button is rapidly tapped twice while the app window is not active yet, for example while dismissing the iOS Control Center.

The race condition happens due to the SDK cancelling the previous Web Auth transaction (when one exists) right before replacing it with a new one. Cancelling a transaction is an async operation as it leads to an error being reported via the result callback, and it might not complete before the new transaction fails too (because the app window is not active), leading to the continuation callback being called twice.

Besides no longer attempting to cancel the previous transaction (which is not really necessary, as the transaction is getting replaced), the changes also ensure the transaction is always cleared before calling the continuation callback –as it should.

📎 References

Fixes #729

🎯 Testing

The changes were tested manually with an iPhone 11 Pro running iOS 15.6, with Xcode 13.4.1 (13F100). The changes were profiled as well to check that no memory leak was introduced.

@Widcket Widcket requested a review from a team as a code owner July 28, 2022 21:32
@Widcket Widcket merged commit 97d6338 into master Jul 29, 2022
@Widcket Widcket deleted the fix/async-await-race-condition branch July 29, 2022 10:00
@Widcket Widcket mentioned this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Application crash in async start method when completion handler is invoked twice
2 participants