Skip to content

Commit de47bf8

Browse files
authored
Enable strict concurrency checking for NIOHTTP1Server (#3132)
### Motivation: To ensure `NIOHTTP1Server` concurrency safety. ### Modifications: * Enable strict concurrency checking in the package manifest. * User synchronous operations in pipeline configurations ### Result: Builds will warn and CI will fail if regressions are introduced.
1 parent 4f2d42f commit de47bf8

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ let package = Package(
319319
"NIOHTTP1",
320320
"NIOConcurrencyHelpers",
321321
],
322-
exclude: ["README.md"]
322+
exclude: ["README.md"],
323+
swiftSettings: strictConcurrencySettings
323324
),
324325
.executableTarget(
325326
name: "NIOHTTP1Client",

Sources/NIOHTTP1Client/main.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ let bootstrap = ClientBootstrap(group: group)
8181
// Enable SO_REUSEADDR.
8282
.channelOption(.socketOption(.so_reuseaddr), value: 1)
8383
.channelInitializer { channel in
84-
channel.pipeline.addHTTPClientHandlers(
85-
position: .first,
86-
leftOverBytesStrategy: .fireError
87-
).flatMap {
88-
channel.pipeline.addHandler(HTTPEchoHandler())
84+
channel.eventLoop.makeCompletedFuture {
85+
try channel.pipeline.syncOperations.addHTTPClientHandlers(
86+
position: .first,
87+
leftOverBytesStrategy: .fireError
88+
)
89+
try channel.pipeline.syncOperations.addHandler(HTTPEchoHandler())
8990
}
9091
}
9192
defer {

Sources/NIOHTTP1Server/main.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,8 @@ default:
631631
}
632632

633633
func childChannelInitializer(channel: Channel) -> EventLoopFuture<Void> {
634-
channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).flatMap {
635-
channel.pipeline.addHandler(HTTPHandler(fileIO: fileIO, htdocsPath: htdocs))
634+
channel.pipeline.configureHTTPServerPipeline(withErrorHandling: true).flatMapThrowing {
635+
try channel.pipeline.syncOperations.addHandler(HTTPHandler(fileIO: fileIO, htdocsPath: htdocs))
636636
}
637637
}
638638

0 commit comments

Comments
 (0)