Skip to content

fix HTTPCookieStorage threading issues #1182

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
Sep 21, 2017
Merged

fix HTTPCookieStorage threading issues #1182

merged 1 commit into from
Sep 21, 2017

Conversation

weissi
Copy link
Contributor

@weissi weissi commented Aug 21, 2017

HTTPCookieStorage isn't thread-safe at all but should be.

@weissi weissi requested a review from parkera August 21, 2017 16:51
@weissi
Copy link
Contributor Author

weissi commented Aug 21, 2017

@swift-ci please test

@ianpartridge
Copy link
Contributor

@mamabusi FYI

@weissi weissi requested a review from pushkarnk August 23, 2017 10:52
@weissi
Copy link
Contributor Author

weissi commented Aug 23, 2017

@parkera / @pushkarnk sorry for prodding, mind letting me know what you think here? I want to some more concurrency fixes and the more open PRs I have in this area the harder it gets as they'll start colliding.

@@ -103,10 +121,12 @@ open class HTTPCookieStorage: NSObject {
*/
open class var shared: HTTPCookieStorage {
get {
if sharedStorage == nil {
sharedStorage = HTTPCookieStorage(cookieStorageName: "shared")
return sharedSyncQ.sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks like a dispatch_once style; shouldn't that be fine as a lazy var?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

@weissi - How about open static var shared: HTTPCookieStorage?

if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
dispatchPrecondition(condition: DispatchPredicate.onQueue(self.syncQ))
}
return self._allCookies
Copy link
Contributor

Choose a reason for hiding this comment

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

self. is not needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what's wrong with the self.? I think that's actually a very important piece of information. Otherwise it just looks like a local variable. The self. makes it very implicit that this is a class property and I believe that makes it more obvious to others that there are possible concurrency concerns.

if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
dispatchPrecondition(condition: DispatchPredicate.onQueue(self.syncQ))
}
self._allCookies = newValue
Copy link
Contributor

Choose a reason for hiding this comment

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

again self. is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

see above

for key in cookies0.keys {
if let cookie = createCookie(cookies0[key]!) {
allCookies[key] = cookie
self.syncQ.sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

again self. is redundant

theCookies = Array(self.allCookies.values)
}
return theCookies
return Array(self.syncQ.sync { self.allCookies.values })
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto on self.

@@ -138,7 +160,7 @@ open class HTTPCookieStorage: NSObject {
same name, domain and path, if any.
*/
open func setCookie(_ cookie: HTTPCookie) {
workQueue.sync {
self.syncQ.sync {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto on self.

private var _allCookies: [String: HTTPCookie]
private var allCookies: [String: HTTPCookie] {
get {
if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about linux?

Copy link
Contributor Author

@weissi weissi Sep 11, 2017

Choose a reason for hiding this comment

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

@phausler Linux seems to be handled in the *:

$ cat test.swift
if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
    print("yes")
} else {
    print("no")
}
$ swift test.swift
yes
$ uname -s
Linux

Choose a reason for hiding this comment

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

I agree to @weissi

if #available(OSX 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) {
dispatchPrecondition(condition: DispatchPredicate.onQueue(self.syncQ))
}

Choose a reason for hiding this comment

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

Are we not supporting linux?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the * seems to match Linux

Choose a reason for hiding this comment

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

@weissi - Yup agreed.

Copy link
Member

@pushkarnk pushkarnk left a comment

Choose a reason for hiding this comment

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

LGTM

@pushkarnk
Copy link
Member

@swift-ci please test and merge

@pushkarnk
Copy link
Member

******************** TEST 'Swift(linux-x86_64) :: ClangImporter/clang_builtins.swift' FAILED ********************

@weissi
Copy link
Contributor Author

weissi commented Sep 21, 2017

clang: �[0;1;31merror: �[0mno such file or directory: 'tools/SourceKit/tools/sourcekitd-test/CMakeFiles/sourcekitd-test.dir/sourcekitd-test.cpp.o'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'tools/SourceKit/tools/sourcekitd-test/CMakeFiles/sourcekitd-test.dir/TestOptions.cpp.o'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'lib/libsourcekitdInProc.so'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'lib/swift/linux/libswiftCore.so'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'lib/libSourceKitSupport.a'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'lib/libswiftBasic.a'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'lib/libswiftDemangling.a'�[0m
clang: �[0;1;31merror: �[0mno such file or directory: 'lib/libswiftSyntax.a'�[0m

there seem to be lots of files missing for some reason. Suspecting something went wrong with Jenkins' workspace. Retrying the tests.

@weissi
Copy link
Contributor Author

weissi commented Sep 21, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit 6a1f875 into swiftlang:master Sep 21, 2017
@weissi weissi deleted the jw-fix-httpcookiestorage-threading branch September 21, 2017 10:52
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