Skip to content

Commit f3cb498

Browse files
committed
Finally fix Linux stream crashes and logging test timing
- Guard the InputStream/OutputStream throwing helpers against Foundation’s unimplemented streamError on Linux so CC_read/CC_write no longer trigger illegal instructions when the underlying handle is closed; fall back to .unknown while keeping richer errors on Apple platforms. - Make the async sleep helper in Logging.testRollingTimestamp2 @sendable and switch it to Thread.sleep on Linux so detached threads actually delay, restoring deterministic timestamp gaps and removing the Swift 6 warning. It looks like there is an open, but (unsurprisingly) abandoned bug entry at swiftlang/swift-corelibs-foundation#3956
1 parent ce5c0ab commit f3cb498

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Sources/CornucopiaCore/Extensions/InputStream/InputStream+ThrowingRead.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ extension InputStream {
2121
guard nRead > 0 else {
2222
switch nRead {
2323
case 0: throw Exception.eof
24-
default: throw self.streamError ?? Exception.unknown
24+
default:
25+
#if os(Linux)
26+
throw Exception.unknown
27+
#else
28+
throw self.streamError ?? Exception.unknown
29+
#endif
2530
}
2631
}
2732
return nRead

Sources/CornucopiaCore/Extensions/OutputStream/OutputStream+ThrowingWrite.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ extension OutputStream {
2020
guard nWritten > 0 else {
2121
switch nWritten {
2222
case 0: throw Exception.eof
23-
default: throw self.streamError ?? Exception.unknown
23+
default:
24+
#if os(Linux)
25+
throw Exception.unknown
26+
#else
27+
throw self.streamError ?? Exception.unknown
28+
#endif
2429
}
2530
}
2631
return nWritten

Tests/CornucopiaCoreTests/Logging/LogFile.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,15 @@ class Logging: XCTestCase {
118118

119119
func testRollingTimestamp2() throws {
120120

121-
func sleep(forTimeInterval t: TimeInterval) {
121+
@Sendable func sleep(forTimeInterval t: TimeInterval) {
122+
#if os(Linux)
123+
Thread.sleep(forTimeInterval: t)
124+
#else
122125
let sema = DispatchSemaphore(value: 0)
123126
let t = Timer(timeInterval: t, repeats: false) { _ in sema.signal() }
124127
RunLoop.main.add(t, forMode: .common)
125128
sema.wait()
129+
#endif
126130
}
127131

128132
let path = "/tmp/logging-test/timestamps2.txt"

0 commit comments

Comments
 (0)