-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Thread safety for URLSession #1210
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
Conversation
9993672
to
35a309e
Compare
@swift-ci please test |
@@ -192,6 +192,7 @@ public let NSURLSessionTransferSizeUnknown: Int64 = -1 | |||
open class URLSession : NSObject { | |||
fileprivate let _configuration: _Configuration | |||
fileprivate let multiHandle: _MultiHandle | |||
fileprivate let taskIdentifierLock = NSLock() |
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.
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.
I’ve switched to using the workQueue for consistency
@@ -192,6 +192,7 @@ public let NSURLSessionTransferSizeUnknown: Int64 = -1 | |||
open class URLSession : NSObject { | |||
fileprivate let _configuration: _Configuration | |||
fileprivate let multiHandle: _MultiHandle | |||
fileprivate let taskIdentifierLock = NSLock() |
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.
also: the sessionDescription
and delegate
properties are also mutable and accessible from the outside. I suppose the should be locked too.
@swift-ci please test |
@swift-ci please test and merge |
cc @saiHemak |
Thanks @pushkarnk, Are we any closer to merging #1198? Is there anything more I can do? |
Hi Apple,
I’ve been seeing assertion failures using a URLSession from multiple threads on this line. This PR makes a small change so allocation of the taskIdentifier in URLSession is thread safe.
Thanks.