Skip to content

Fix for URLSession registers native protocol classes for each new session #1030

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

Fix for URLSession registers native protocol classes for each new session #1030

merged 1 commit into from
Jun 21, 2017

Conversation

nethraravindran
Copy link
Contributor

No description provided.

Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

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

Please use a different mechanism, such as dispatch_once, to ensure they are only added a single time, rather than special casing (and breaking) the API.

@@ -471,7 +473,7 @@ open class URLProtocol : NSObject {
}

internal class func getProtocols() -> [AnyClass]? {
return _registeredProtocolClasses
return _nativeProtocolClasses
Copy link
Contributor

Choose a reason for hiding this comment

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

This is going to break anyone who registers their protocol classes via the supported APIs, right? Creating a special-case for HTTPURLProtocol does not look like the way to fix this problem. Instead, the protocol classes should be added using a dispatch_once style mechanism, so that they aren't added each time.

@nethraravindran
Copy link
Contributor Author

@alblue Thanks for the review comments. I have used static let which works like dispatch_once.
https://stackoverflow.com/questions/37801407/whither-dispatch-once-in-swift-3?answertab=votes#tab-top

@pushkarnk
Copy link
Member

@swift-ci please test

@@ -191,6 +191,10 @@ open class URLSession : NSObject {
internal let taskRegistry = URLSession._TaskRegistry()
fileprivate let identifier: Int32
fileprivate var invalidated = false
fileprivate static let registerProtocols: Void = {
Copy link
Member

Choose a reason for hiding this comment

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

Is the Void necessary here?

@pushkarnk
Copy link
Member

Thanks @nethraravindran and @alblue

@swift-ci please test and merge

@pushkarnk
Copy link
Member

@swift-ci please test and merge

@pushkarnk
Copy link
Member

Some unrelated tests seem to have failed:

TestFoundation/TestMassFormatter.swift:102: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("lb") is not equal to ("kg") - 
TestFoundation/TestMassFormatter.swift:103: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("pound") is not equal to ("kilogram") - 
TestFoundation/TestMassFormatter.swift:105: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("lb") is not equal to ("kg") - 
TestFoundation/TestMassFormatter.swift:106: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("pound") is not equal to ("kilogram") - 
TestFoundation/TestMassFormatter.swift:108: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("oz") is not equal to ("g") - 
TestFoundation/TestMassFormatter.swift:109: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("ounce") is not equal to ("gram") - 
TestFoundation/TestMassFormatter.swift:111: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("lb") is not equal to ("g") - 
TestFoundation/TestMassFormatter.swift:112: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("pound") is not equal to ("gram") - 
TestFoundation/TestMassFormatter.swift:114: error: TestMassFormatter.test_unitStringFromKilograms : XCTAssertEqual failed: ("lb") is not equal to ("kg")

@pushkarnk
Copy link
Member

Looks like the reason is #1043

@pushkarnk
Copy link
Member

@swift-ci please test and merge

1 similar comment
@pushkarnk
Copy link
Member

@swift-ci please test and merge

@swift-ci swift-ci merged commit 031a257 into swiftlang:master Jun 21, 2017
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.

4 participants