You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ProcessInfo is documented to be thread-safe. Unfortunately, on Linux it isn't and calling ProcessInfo.processInfo.hostName may actually lead to crashes.
For example, if you run this program in a loop, you'll see a segfault (or some other crash) after a while)
import Foundation
import Dispatch
let threads = 60
let sem1 = DispatchSemaphore(value: 0)
let sem2 = DispatchSemaphore(value: 0)
let g = DispatchGroup()
(0..<threads).forEach { index in
DispatchQueue(label: "\(index)").async(group: g) {
sem1.signal()
// All threads should be parked here
sem2.wait()
precondition(ProcessInfo.processInfo.hostName.utf8.count > 0)
}
}
(0..<threads).forEach { index in
sem1.wait()
}
(0..<threads).forEach { index in
sem2.signal()
}
g.wait()
$ docker run -it --rm -v "$PWD:$PWD" -w "$PWD" swift:5.5-focal bash -c 'swiftc repro.swift && while ./repro; do echo -n .; done'
.............bash: line 1: 833 Segmentation fault ./repro
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: ce7ed0ffe39e9c016347978e5e6bd8db
Issue Description:
ProcessInfo
is documented to be thread-safe. Unfortunately, on Linux it isn't and callingProcessInfo.processInfo.hostName
may actually lead to crashes.The problem is that
ProcessInfo
callsHost.current().name
(https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/Foundation/ProcessInfo.swift#L61)Host.name
then callsHost.names
(https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/Foundation/Host.swift#L335) which is mutating the instance without any synchronisation on the singletonHost._current
.For example, if you run this program in a loop, you'll see a segfault (or some other crash) after a while)
The text was updated successfully, but these errors were encountered: