From bdc82eb6393789b16c69987ab1db0762c7297081 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Thu, 6 Mar 2025 09:30:36 +0000 Subject: [PATCH 1/2] Enable strict concurrency checking for NIOTestUtils Motivation: To ensure `NIOTestUtils` concurrency safety. Modifications: * Enable strict concurrency checking in the package manifest. * `NIOHTTP1TestServer` does pipeline configuration as synchronous operations. Result: `NIOTestUtils` does not warn of concurrency issues, builds will warn and CI will fail if regressions are introduced. --- Package.swift | 3 ++- Sources/NIOTestUtils/NIOHTTP1TestServer.swift | 18 ++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/Package.swift b/Package.swift index 0a57fa70d12..71b69bd15fa 100644 --- a/Package.swift +++ b/Package.swift @@ -233,7 +233,8 @@ let package = Package( "NIOEmbedded", "NIOHTTP1", swiftAtomics, - ] + ], + swiftSettings: strictConcurrencySettings ), .target( name: "_NIOFileSystem", diff --git a/Sources/NIOTestUtils/NIOHTTP1TestServer.swift b/Sources/NIOTestUtils/NIOHTTP1TestServer.swift index 6687d6e8838..2a2676cabb7 100644 --- a/Sources/NIOTestUtils/NIOHTTP1TestServer.swift +++ b/Sources/NIOTestUtils/NIOHTTP1TestServer.swift @@ -263,18 +263,16 @@ public final class NIOHTTP1TestServer { self.handleChannels() return } - channel.pipeline.configureHTTPServerPipeline().flatMap { + do { + try channel.pipeline.syncOperations.configureHTTPServerPipeline() if self.aggregateBody { - return channel.pipeline.addHandler(AggregateBodyHandler()) - } else { - return self.eventLoop.makeSucceededVoidFuture() + try channel.pipeline.syncOperations.addHandler(AggregateBodyHandler()) } - }.flatMap { - channel.pipeline.addHandler(WebServerHandler(webServer: self)) - }.flatMap { - channel.pipeline.addHandler(TransformerHandler()) - }.whenSuccess { - _ = channel.setOption(.autoRead, value: true) + try channel.pipeline.syncOperations.addHandler(WebServerHandler(webServer: self)) + try channel.pipeline.syncOperations.addHandler(TransformerHandler()) + _ = try channel.syncOptions!.setOption(.autoRead, value: true) + } catch { + assertionFailure("Channel initialization failed with: \(error)") } } From ddef4954ca476d4cadf79f2ee6973cc267f6037d Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Fri, 7 Mar 2025 09:56:56 +0000 Subject: [PATCH 2/2] NIOHTTP1TestServer fatalErrors on channel init failure --- Sources/NIOTestUtils/NIOHTTP1TestServer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/NIOTestUtils/NIOHTTP1TestServer.swift b/Sources/NIOTestUtils/NIOHTTP1TestServer.swift index 2a2676cabb7..08712e2f95b 100644 --- a/Sources/NIOTestUtils/NIOHTTP1TestServer.swift +++ b/Sources/NIOTestUtils/NIOHTTP1TestServer.swift @@ -272,7 +272,7 @@ public final class NIOHTTP1TestServer { try channel.pipeline.syncOperations.addHandler(TransformerHandler()) _ = try channel.syncOptions!.setOption(.autoRead, value: true) } catch { - assertionFailure("Channel initialization failed with: \(error)") + fatalError("Channel initialization failed with: \(error)") } }