-
Notifications
You must be signed in to change notification settings - Fork 1k
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(ios): don't call urlSchemeTask methods if it was stopped #7453
Conversation
func withTask(_ schemeTask: WKURLSchemeTask, action: @escaping () -> Void) { | ||
lock.withLock { | ||
if tasks.contains(schemeTask.hash) { | ||
DispatchQueue.main.async { | ||
action() | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using lock.withLock
, we should probably use the individual locking methods so the code would look like this:
func withTask(_ schemeTask: WKURLSchemeTask, action: @escaping () -> Void) {
lock.lock()
if tasks.contains(schemeTask.hash) {
DispatchQueue.main.async {
action()
lock.unlock()
}
} else {
lock.unlock()
}
}
In it's currently state, the lock is can actually be released before the action is run because DispatchQueue.main.async
returns immediately and would still allow for the race condition to occur.
keep track of urlSchemeTasks and don't call their methods if the task was stopped
closes #7404