Skip to content

Commit 1265185

Browse files
authored
Unbreak CI (swift-server#800)
# Motivation The NIO 2.78 release introduced a bunch of new warnings. These warnings cause us a bunch of trouble, so we should fix them. # Modifications Mostly use a bunch of assumeIsolated() and syncOperations. # Result CI passes again. Note that Swift 6 has _many_ more warnings than this, but we expect more to come and we aren't using warnings-as-errors on that mode at the moment. We'll be cleaning that up soon.
1 parent f77cc00 commit 1265185

8 files changed

+56
-44
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
.library(name: "AsyncHTTPClient", targets: ["AsyncHTTPClient"])
2222
],
2323
dependencies: [
24-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.71.0"),
24+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.78.0"),
2525
.package(url: "https://github.com/apple/swift-nio-ssl.git", from: "2.27.1"),
2626
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.19.0"),
2727
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.13.0"),

Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift

+12-12
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ extension HTTPConnectionPool.ConnectionFactory {
249249

250250
// The proxyEstablishedFuture is set as soon as the HTTP1ProxyConnectHandler is in a
251251
// pipeline. It is created in HTTP1ProxyConnectHandler's handlerAdded method.
252-
return proxyHandler.proxyEstablishedFuture!.flatMap {
253-
channel.pipeline.removeHandler(proxyHandler).flatMap {
254-
channel.pipeline.removeHandler(decoder).flatMap {
255-
channel.pipeline.removeHandler(encoder)
256-
}
257-
}
252+
return proxyHandler.proxyEstablishedFuture!.assumeIsolated().flatMap {
253+
channel.pipeline.syncOperations.removeHandler(proxyHandler).assumeIsolated().flatMap {
254+
channel.pipeline.syncOperations.removeHandler(decoder).assumeIsolated().flatMap {
255+
channel.pipeline.syncOperations.removeHandler(encoder)
256+
}.nonisolated()
257+
}.nonisolated()
258258
}.flatMap {
259259
self.setupTLSInProxyConnectionIfNeeded(channel, deadline: deadline, logger: logger)
260-
}
260+
}.nonisolated()
261261
}
262262
}
263263

@@ -291,13 +291,13 @@ extension HTTPConnectionPool.ConnectionFactory {
291291

292292
// The socksEstablishedFuture is set as soon as the SOCKSEventsHandler is in a
293293
// pipeline. It is created in SOCKSEventsHandler's handlerAdded method.
294-
return socksEventHandler.socksEstablishedFuture!.flatMap {
295-
channel.pipeline.removeHandler(socksEventHandler).flatMap {
296-
channel.pipeline.removeHandler(socksConnectHandler)
297-
}
294+
return socksEventHandler.socksEstablishedFuture!.assumeIsolated().flatMap {
295+
channel.pipeline.syncOperations.removeHandler(socksEventHandler).assumeIsolated().flatMap {
296+
channel.pipeline.syncOperations.removeHandler(socksConnectHandler)
297+
}.nonisolated()
298298
}.flatMap {
299299
self.setupTLSInProxyConnectionIfNeeded(channel, deadline: deadline, logger: logger)
300-
}
300+
}.nonisolated()
301301
}
302302
}
303303

Sources/AsyncHTTPClient/FileDownloadDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public final class FileDownloadDelegate: HTTPClientResponseDelegate {
167167
}
168168
} else {
169169
let fileHandleFuture = io.openFile(
170-
path: self.filePath,
170+
_deprecatedPath: self.filePath,
171171
mode: .write,
172172
flags: .allowFileCreation(),
173173
eventLoop: task.eventLoop

Tests/AsyncHTTPClientTests/AsyncAwaitEndToEndTests.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,9 @@ final class AsyncAwaitEndToEndTests: XCTestCase {
595595
defer { XCTAssertNoThrow(try serverGroup.syncShutdownGracefully()) }
596596
let server = ServerBootstrap(group: serverGroup)
597597
.childChannelInitializer { channel in
598-
channel.pipeline.addHandler(NIOSSLServerHandler(context: sslContext))
598+
channel.eventLoop.makeCompletedFuture {
599+
try channel.pipeline.syncOperations.addHandler(NIOSSLServerHandler(context: sslContext))
600+
}
599601
}
600602
let serverChannel = try await server.bind(host: "localhost", port: 0).get()
601603
defer { XCTAssertNoThrow(try serverChannel.close().wait()) }

Tests/AsyncHTTPClientTests/EmbeddedChannel+HTTPConvenience.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ extension EmbeddedChannel {
8787
let decoder = try self.pipeline.syncOperations.handler(type: ByteToMessageHandler<HTTPResponseDecoder>.self)
8888
let encoder = try self.pipeline.syncOperations.handler(type: HTTPRequestEncoder.self)
8989

90-
let removeDecoderFuture = self.pipeline.removeHandler(decoder)
91-
let removeEncoderFuture = self.pipeline.removeHandler(encoder)
90+
let removeDecoderFuture = self.pipeline.syncOperations.removeHandler(decoder)
91+
let removeEncoderFuture = self.pipeline.syncOperations.removeHandler(encoder)
9292

9393
self.embeddedEventLoop.run()
9494

Tests/AsyncHTTPClientTests/HTTPClientTestUtils.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -544,12 +544,12 @@ where
544544
try sync.addHandler(requestDecoder)
545545
try sync.addHandler(proxySimulator)
546546

547-
promise.futureResult.flatMap { _ in
548-
channel.pipeline.removeHandler(proxySimulator)
547+
promise.futureResult.assumeIsolated().flatMap { _ in
548+
channel.pipeline.syncOperations.removeHandler(proxySimulator)
549549
}.flatMap { _ in
550-
channel.pipeline.removeHandler(responseEncoder)
550+
channel.pipeline.syncOperations.removeHandler(responseEncoder)
551551
}.flatMap { _ in
552-
channel.pipeline.removeHandler(requestDecoder)
552+
channel.pipeline.syncOperations.removeHandler(requestDecoder)
553553
}.whenComplete { result in
554554
switch result {
555555
case .failure:
@@ -653,8 +653,8 @@ where
653653
}
654654
}
655655

656+
try channel.pipeline.syncOperations.addHandler(sslHandler)
656657
try channel.pipeline.syncOperations.addHandler(alpnHandler)
657-
try channel.pipeline.syncOperations.addHandler(sslHandler, position: .before(alpnHandler))
658658
}
659659

660660
func shutdown() throws {

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,9 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
16001600

16011601
let server = ServerBootstrap(group: serverGroup)
16021602
.childChannelInitializer { channel in
1603-
channel.pipeline.addHandler(NIOSSLServerHandler(context: sslContext))
1603+
channel.eventLoop.makeCompletedFuture {
1604+
try channel.pipeline.syncOperations.addHandler(NIOSSLServerHandler(context: sslContext))
1605+
}
16041606
}
16051607
let serverChannel = try server.bind(host: "localhost", port: 0).wait()
16061608
defer { XCTAssertNoThrow(try serverChannel.close().wait()) }
@@ -1642,7 +1644,9 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
16421644

16431645
let server = ServerBootstrap(group: serverGroup)
16441646
.childChannelInitializer { channel in
1645-
channel.pipeline.addHandler(NIOSSLServerHandler(context: sslContext))
1647+
channel.eventLoop.makeCompletedFuture {
1648+
try channel.pipeline.syncOperations.addHandler(NIOSSLServerHandler(context: sslContext))
1649+
}
16461650
}
16471651
let serverChannel = try server.bind(host: "localhost", port: 0).wait()
16481652
defer { XCTAssertNoThrow(try serverChannel.close().wait()) }

Tests/AsyncHTTPClientTests/SOCKSTestUtils.swift

+26-20
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,19 @@ class MockSOCKSServer {
5959
bootstrap = ServerBootstrap(group: elg)
6060
.serverChannelOption(ChannelOptions.socket(SocketOptionLevel(SOL_SOCKET), SO_REUSEADDR), value: 1)
6161
.childChannelInitializer { channel in
62-
let handshakeHandler = SOCKSServerHandshakeHandler()
63-
return channel.pipeline.addHandlers([
64-
handshakeHandler,
65-
SOCKSTestHandler(handshakeHandler: handshakeHandler),
66-
TestHTTPServer(
67-
expectedURL: expectedURL,
68-
expectedResponse: expectedResponse,
69-
file: file,
70-
line: line
71-
),
72-
])
62+
channel.eventLoop.makeCompletedFuture {
63+
let handshakeHandler = SOCKSServerHandshakeHandler()
64+
try channel.pipeline.syncOperations.addHandlers([
65+
handshakeHandler,
66+
SOCKSTestHandler(handshakeHandler: handshakeHandler),
67+
TestHTTPServer(
68+
expectedURL: expectedURL,
69+
expectedResponse: expectedResponse,
70+
file: file,
71+
line: line
72+
),
73+
])
74+
}
7375
}
7476
}
7577
self.channel = try bootstrap.bind(host: "localhost", port: 0).wait()
@@ -112,15 +114,19 @@ class SOCKSTestHandler: ChannelInboundHandler, RemovableChannelHandler {
112114
),
113115
promise: nil
114116
)
115-
context.channel.pipeline.addHandlers(
116-
[
117-
ByteToMessageHandler(HTTPRequestDecoder()),
118-
HTTPResponseEncoder(),
119-
],
120-
position: .after(self)
121-
).whenSuccess {
122-
context.channel.pipeline.removeHandler(self, promise: nil)
123-
context.channel.pipeline.removeHandler(self.handshakeHandler, promise: nil)
117+
118+
do {
119+
try context.channel.pipeline.syncOperations.addHandlers(
120+
[
121+
ByteToMessageHandler(HTTPRequestDecoder()),
122+
HTTPResponseEncoder(),
123+
],
124+
position: .after(self)
125+
)
126+
context.channel.pipeline.syncOperations.removeHandler(self, promise: nil)
127+
context.channel.pipeline.syncOperations.removeHandler(self.handshakeHandler, promise: nil)
128+
} catch {
129+
context.fireErrorCaught(error)
124130
}
125131
}
126132
}

0 commit comments

Comments
 (0)