Skip to content

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

Merged
merged 2 commits into from
Sep 14, 2017
Merged

Conversation

johnno1962
Copy link
Contributor

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.

@alblue
Copy link
Contributor

alblue commented Sep 11, 2017

@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()
Copy link
Contributor

Choose a reason for hiding this comment

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

my only question is what is the preferred way, NSLock or a dispatch queue? I think we should be consistent. @phausler / @parkera do we have a preferred option?

Copy link
Contributor Author

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()
Copy link
Contributor

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.

@ianpartridge
Copy link
Contributor

@swift-ci please test

@pushkarnk
Copy link
Member

@swift-ci please test and merge

@pushkarnk
Copy link
Member

cc @saiHemak

@swift-ci swift-ci merged commit 3618f00 into swiftlang:master Sep 14, 2017
@johnno1962
Copy link
Contributor Author

Thanks @pushkarnk, Are we any closer to merging #1198? Is there anything more I can do?

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.

6 participants