From fb5718bb56595b1865be85367f314b2b382d80ba Mon Sep 17 00:00:00 2001 From: Xyan Bhatnagar Date: Thu, 5 Mar 2026 10:40:11 -0800 Subject: [PATCH 1/2] Catch the error from a client disconnect due to stalled response --- .../HTTPServerForTesting/TestHTTPServer.swift | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift b/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift index 059556a..de31bee 100644 --- a/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift +++ b/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift @@ -329,23 +329,31 @@ func serve(server: NIOHTTPServer) async throws { return nil } case "/stall": - // Wait for an hour (effectively never giving an answer) - try await Task.sleep(for: .seconds(60 * 60)) - assertionFailure("Not expected to complete hour-long wait") - case "/stall_body": - // Send headers and partial body - let responseBodyAndTrailers = try await responseSender.send(.init(status: .ok)) - - try await responseBodyAndTrailers.produceAndConclude { responseBody in - var responseBody = responseBody - try await responseBody.write([UInt8](repeating: UInt8(ascii: "A"), count: 1000).span) - + do { // Wait for an hour (effectively never giving an answer) try await Task.sleep(for: .seconds(60 * 60)) - assertionFailure("Not expected to complete hour-long wait") + } catch { + // It is okay for the client to give up on the connection due to the stall. + } + case "/stall_body": + // Send headers and partial body + let responseBodyAndTrailers = try await responseSender.send(.init(status: .ok)) - return nil + do { + try await responseBodyAndTrailers.produceAndConclude { responseBody in + var responseBody = responseBody + try await responseBody.write([UInt8](repeating: UInt8(ascii: "A"), count: 1000).span) + + // Wait for an hour (effectively never giving an answer) + try await Task.sleep(for: .seconds(60 * 60)) + + assertionFailure("Not expected to complete hour-long wait") + + return nil + } + } catch { + // It is okay for the client to give up on the connection due to the stall. } case "/1mb_body": let responseBodyAndTrailers = try await responseSender.send(.init(status: .ok)) From 2d44a0e31257fa4e43addbe791b3f2859830068d Mon Sep 17 00:00:00 2001 From: Xyan Bhatnagar Date: Thu, 5 Mar 2026 10:57:13 -0800 Subject: [PATCH 2/2] swift-format --- .../HTTPServerForTesting/TestHTTPServer.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift b/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift index de31bee..4bc4e79 100644 --- a/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift +++ b/Sources/HTTPClientConformance/HTTPServerForTesting/TestHTTPServer.swift @@ -344,12 +344,12 @@ func serve(server: NIOHTTPServer) async throws { try await responseBodyAndTrailers.produceAndConclude { responseBody in var responseBody = responseBody try await responseBody.write([UInt8](repeating: UInt8(ascii: "A"), count: 1000).span) - + // Wait for an hour (effectively never giving an answer) try await Task.sleep(for: .seconds(60 * 60)) - + assertionFailure("Not expected to complete hour-long wait") - + return nil } } catch {