Skip to content

Guard against racy access to NSError.setUserInfoValueProvider. #4280

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
Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion stdlib/public/SDK/Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public extension Error {
}
}

internal let _errorDomainUserInfoProviderQueue = DispatchQueue(
label: "SwiftFoundation._errorDomainUserInfoProviderQueue")

/// Retrieve the default userInfo dictionary for a given error.
@_silgen_name("swift_Foundation_getErrorDefaultUserInfo")
public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
Expand All @@ -149,7 +152,8 @@ public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
// user-info value providers.
let domain = error._domain
if domain != NSCocoaErrorDomain {
if NSError.userInfoValueProvider(forDomain: domain) == nil {
_errorDomainUserInfoProviderQueue.sync {
if NSError.userInfoValueProvider(forDomain: domain) != nil { return }
NSError.setUserInfoValueProvider(forDomain: domain) { (nsError, key) in
let error = nsError as Error

Expand Down
1 change: 0 additions & 1 deletion validation-test/stdlib/ErrorProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: rdar27541751
// REQUIRES: objc_interop

import SwiftPrivate
Expand Down