From 3bfffb2a5b054f214e27dd46b7b61f491262a39b Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Sun, 9 Nov 2025 07:04:50 +0100 Subject: [PATCH 1/3] fixed fatalError when connection was lost immediately after sending request - fixes https://github.com/swiftlang/swift-corelibs-foundation/issues/5285 --- .../FoundationNetworking/URLSession/NativeProtocol.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/FoundationNetworking/URLSession/NativeProtocol.swift b/Sources/FoundationNetworking/URLSession/NativeProtocol.swift index ad6836dc9a..ba0af7e9c1 100644 --- a/Sources/FoundationNetworking/URLSession/NativeProtocol.swift +++ b/Sources/FoundationNetworking/URLSession/NativeProtocol.swift @@ -237,7 +237,11 @@ internal class _NativeProtocol: URLProtocol, _EasyHandleDelegate { } guard let response = ts.response else { - fatalError("Transfer completed, but there's no response.") + internalState = .transferFailed + let error = NSError(domain: NSURLErrorDomain, code: NSURLErrorNetworkConnectionLost, + userInfo: [NSLocalizedDescriptionKey: "The network connection was lost."]) + failWith(error: error, request: request) + return } internalState = .transferCompleted(response: response, bodyDataDrain: ts.bodyDataDrain) let action = completionAction(forCompletedRequest: request, response: response) From 4bff09c190cb0ee4e760e8427e12b8646d10a7ec Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Sun, 23 Nov 2025 09:40:33 +0100 Subject: [PATCH 2/3] fixed spacing --- Sources/FoundationNetworking/URLSession/NativeProtocol.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FoundationNetworking/URLSession/NativeProtocol.swift b/Sources/FoundationNetworking/URLSession/NativeProtocol.swift index ba0af7e9c1..5c278d9958 100644 --- a/Sources/FoundationNetworking/URLSession/NativeProtocol.swift +++ b/Sources/FoundationNetworking/URLSession/NativeProtocol.swift @@ -239,7 +239,7 @@ internal class _NativeProtocol: URLProtocol, _EasyHandleDelegate { guard let response = ts.response else { internalState = .transferFailed let error = NSError(domain: NSURLErrorDomain, code: NSURLErrorNetworkConnectionLost, - userInfo: [NSLocalizedDescriptionKey: "The network connection was lost."]) + userInfo: [NSLocalizedDescriptionKey: "The network connection was lost."]) failWith(error: error, request: request) return } From c0447993f97de6045ba874606aced7903da69cd1 Mon Sep 17 00:00:00 2001 From: Patrick Stein Date: Sun, 14 Dec 2025 06:50:27 +0100 Subject: [PATCH 3/3] Changed description back to the original one. --- Sources/FoundationNetworking/URLSession/NativeProtocol.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/FoundationNetworking/URLSession/NativeProtocol.swift b/Sources/FoundationNetworking/URLSession/NativeProtocol.swift index 5c278d9958..8bcdef00b1 100644 --- a/Sources/FoundationNetworking/URLSession/NativeProtocol.swift +++ b/Sources/FoundationNetworking/URLSession/NativeProtocol.swift @@ -239,7 +239,7 @@ internal class _NativeProtocol: URLProtocol, _EasyHandleDelegate { guard let response = ts.response else { internalState = .transferFailed let error = NSError(domain: NSURLErrorDomain, code: NSURLErrorNetworkConnectionLost, - userInfo: [NSLocalizedDescriptionKey: "The network connection was lost."]) + userInfo: [NSLocalizedDescriptionKey: "Transfer completed, but there's no response."]) failWith(error: error, request: request) return }