Skip to content

Commit 2e87e5e

Browse files
authored
Merge pull request swiftlang#5016 from jrflat/urlsession-threading-crash
Use a shared queue for URLSessions to prevent crash during _MultiHandle.deinit
2 parents 15ee5c3 + a757413 commit 2e87e5e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/FoundationNetworking/URLSession/URLSession.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ open class URLSession : NSObject {
217217
return URLSession(configuration: configuration, delegate: nil, delegateQueue: nil)
218218
}()
219219

220+
private static let sharedQueue = DispatchQueue(label: "org.swift.URLSession.SharedQueue")
221+
220222
/*
221223
* Customization of URLSession occurs during creation of a new session.
222224
* If you only need to use the convenience routines with custom
@@ -227,7 +229,7 @@ open class URLSession : NSObject {
227229
public /*not inherited*/ init(configuration: URLSessionConfiguration) {
228230
initializeLibcurl()
229231
identifier = nextSessionIdentifier()
230-
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>")
232+
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>", target: Self.sharedQueue)
231233
self.delegateQueue = OperationQueue()
232234
self.delegateQueue.maxConcurrentOperationCount = 1
233235
self.delegate = nil
@@ -249,7 +251,7 @@ open class URLSession : NSObject {
249251
public /*not inherited*/ init(configuration: URLSessionConfiguration, delegate: URLSessionDelegate?, delegateQueue queue: OperationQueue?) {
250252
initializeLibcurl()
251253
identifier = nextSessionIdentifier()
252-
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>")
254+
self.workQueue = DispatchQueue(label: "URLSession<\(identifier)>", target: Self.sharedQueue)
253255
if let _queue = queue {
254256
self.delegateQueue = _queue
255257
} else {

0 commit comments

Comments
 (0)