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(ios): don't call urlSchemeTask methods if it was stopped #7453

Closed
wants to merge 6 commits into from

Conversation

jcesarmobile
Copy link
Member

keep track of urlSchemeTasks and don't call their methods if the task was stopped

closes #7404

@jcesarmobile jcesarmobile changed the title fix(ios): don't return data if task was stopped fix(ios): don't call urlSchemeTask methods if it was stopped May 7, 2024
ios/Capacitor/Capacitor/WebViewAssetHandler.swift Outdated Show resolved Hide resolved
ios/Capacitor/Capacitor/WebViewAssetHandler.swift Outdated Show resolved Hide resolved
ios/Capacitor/Capacitor/WebViewAssetHandler.swift Outdated Show resolved Hide resolved
ios/Capacitor/Capacitor/WebViewAssetHandler.swift Outdated Show resolved Hide resolved
@jcesarmobile jcesarmobile mentioned this pull request May 9, 2024
Comment on lines +602 to +610
func withTask(_ schemeTask: WKURLSchemeTask, action: @escaping () -> Void) {
lock.withLock {
if tasks.contains(schemeTask.hash) {
DispatchQueue.main.async {
action()
}
}
}
}
Copy link
Member

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.

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.

[Bug]: iOS crash in Http Plugin
2 participants