Skip to content

Commit 865b288

Browse files
committed
fix: Pre-iOS 18 crash on queue isolation
1 parent 8a5e3a7 commit 865b288

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

Sources/GoodNetworking/Session/DataTaskProxy.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ import Foundation
5454
self.receivedError = URLError(.unknown)
5555
}
5656

57-
logger.logNetworkEvent(
58-
message: prepareRequestInfo(),
59-
level: receivedError == nil ? .debug : .warning,
60-
file: #file,
61-
line: #line
62-
)
57+
Task { @NetworkActor in
58+
logger.logNetworkEvent(
59+
message: prepareRequestInfo(),
60+
level: receivedError == nil ? .debug : .warning,
61+
file: #file,
62+
line: #line
63+
)
64+
}
6365

6466
continuation?.resume()
6567
continuation = nil

Sources/GoodNetworking/Session/NetworkSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ import Foundation
6767
self.configuration = configuration
6868
self.delegateQueue = operationQueue
6969

70-
// create URLSession lazily, isolated on @NetworkActor, when requested first time
70+
// create URLSession lazily, isolated to @NetworkActor, when requested first time
7171

7272
super.init()
7373
}

Sources/GoodNetworking/Utilities/NetworkActor.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ import Foundation
1818

1919
private static let executor: NetworkActorExecutor = NetworkActorExecutor()
2020

21-
// MARK: - Properties
22-
2321
// MARK: - Computed properties
2422

2523
public nonisolated var unownedExecutor: UnownedSerialExecutor {
@@ -37,9 +35,15 @@ import Foundation
3735
) rethrows -> sending T {
3836
typealias YesActor = @NetworkActor () throws -> sending T
3937
typealias NoActor = () throws -> sending T
40-
41-
NetworkActor.preconditionIsolated()
42-
38+
39+
if #available(iOS 18, *) {
40+
NetworkActor.preconditionIsolated()
41+
} else {
42+
// manual call to checkIsolated() as Swift runtime doesn't
43+
// support custom implementation before iOS 18/26
44+
executor.checkIsolated()
45+
}
46+
4347
return try withoutActuallyEscaping(block) { (_ fn: @escaping YesActor) throws -> sending T in
4448
try unsafeBitCast(fn, to: NoActor.self)()
4549
}

0 commit comments

Comments
 (0)