Skip to content

Use a shared queue for URLSessions to prevent crash during _MultiHandle.deinit #5016

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

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Sources/FoundationNetworking/URLSession/URLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ open class URLSession : NSObject {
return URLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
}()

private static let sharedQueue = DispatchQueue(label: "org.swift.URLSession.SharedQueue")

/*
* Customization of URLSession occurs during creation of a new session.
* If you only need to use the convenience routines with custom
Expand All @@ -227,7 +229,7 @@ open class URLSession : NSObject {
public /*not inherited*/ init(configuration: URLSessionConfiguration) {
initializeLibcurl()
identifier = nextSessionIdentifier()
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>")
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>", target: Self.sharedQueue)
self.delegateQueue = OperationQueue()
self.delegateQueue.maxConcurrentOperationCount = 1
self.delegate = nil
Expand All @@ -249,7 +251,7 @@ open class URLSession : NSObject {
public /*not inherited*/ init(configuration: URLSessionConfiguration, delegate: URLSessionDelegate?, delegateQueue queue: OperationQueue?) {
initializeLibcurl()
identifier = nextSessionIdentifier()
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>")
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>", target: Self.sharedQueue)
if let _queue = queue {
self.delegateQueue = _queue
} else {
Expand Down