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

Avoid racing for accessing originalRequest #1558

Merged
merged 3 commits into from
Oct 28, 2020
Merged

Conversation

onevcat
Copy link
Owner

@onevcat onevcat commented Oct 27, 2020

This patch adds/adjusts some lock behaviors. This should help to avoid racing for accessing originalRequest properties and fix #1511

This patch adds/adjusts some lock behaviors. This should help to avoid racing for accessing originalRequest properties and fix #1511
@@ -92,22 +99,22 @@ class SessionDelegate: NSObject {
}

private func remove(_ task: URLSessionTask) {
lock.lock()
defer { lock.unlock() }

guard let url = task.originalRequest?.url else {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't you want to use task.originalURL here as well? Also in task(for:), so we only ever call task.originalRequest?.url once, and that's in the SessionDataTask init. Then I don't think you need to adjust the locks (or at least I don't think it will affect the behavior)

@onevcat onevcat merged commit 9815fd3 into master Oct 28, 2020
@onevcat onevcat deleted the fix/lock-task-cancellation branch October 28, 2020 14:08
skoduricg pushed a commit to rentpath/Kingfisher that referenced this pull request Sep 24, 2021
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.

Crashes on SessionDelegate.remove() when canceling Download Task
2 participants