Skip to content

Commit 9d87e9c

Browse files
glbrnttaryan-25
andauthored
Bump to swift-nio-quic 0.2.1 (#15)
Motivation: swift-nio-quic tagged a new release with some breaking changes Modifications: - Adopt new API - Translate QUIC errors to HTTP3 errors in the stream channel - Bail out when `self.context` is nil in release queue; this can be reached re-entrantly when a peer attempts to open an invalid stream. This was previously not reachable because of incorrect behavior in swift-nio-quic. Result: Builds and tests pass --------- Co-authored-by: Aryan Shah <aryan_shah@apple.com>
1 parent cfb9db4 commit 9d87e9c

6 files changed

Lines changed: 28 additions & 15 deletions

File tree

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let package = Package(
3535
.package(url: "https://github.com/apple/swift-certificates.git", from: "1.19.3"),
3636
.package(url: "https://github.com/apple/swift-nio-extras.git", from: "1.22.0"),
3737
.package(url: "https://github.com/apple/swift-nio-quic-helpers.git", .upToNextMinor(from: "0.1.0")),
38-
.package(url: "https://github.com/apple/swift-nio-quic.git", .upToNextMinor(from: "0.1.0")),
38+
.package(url: "https://github.com/apple/swift-nio-quic.git", .upToNextMinor(from: "0.2.1")),
3939
],
4040
targets: [
4141
.target(

Sources/NIOHTTP3/HTTP3StreamHandler.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,25 @@ package final class HTTP3StreamHandler: ChannelDuplexHandler {
302302
case .none:
303303
break
304304
}
305+
case let error as QUICConnectionError:
306+
self.logger.trace("Caught CONNECTION_CLOSE")
307+
let h3Code: HTTP3ErrorCode?
308+
if error.isApplication {
309+
// RFC 9114 § 8: "Receipt of an unknown error code MUST be treated as equivalent to
310+
// H3_NO_ERROR."
311+
h3Code = HTTP3ErrorCode(rawValue: error.code)
312+
} else {
313+
h3Code = nil
314+
}
315+
context.fireErrorCaught(
316+
HTTP3Error(
317+
code: .remoteConnectionError,
318+
message: error.reason,
319+
cause: error,
320+
errorCode: h3Code,
321+
location: .here()
322+
)
323+
)
305324
default:
306325
context.fireErrorCaught(error)
307326
}

Sources/NIOHTTP3/HTTP3UnidirectionalStreamTypeDecoderHandler.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ package final class HTTP3UnidirectionalStreamTypeDecoderHandler: ChannelInboundH
6969
/// You should not release the queue before the stream type is known.
7070
private func releaseQueue() {
7171
guard let context = self.context else {
72-
fatalError("Tried to release queue but missing context")
72+
// No context means the stream is closed: no-op.
73+
return
7374
}
75+
7476
// We must call unbufferElement in a loop until `done` is returned
7577
var didFireChannelRead = false
7678
loop: while true {

Tests/H3IntegrationTests/EndToEndTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,10 +1257,10 @@ struct EndToEndTests {
12571257
try $0.channel.pipeline.syncOperations.addHandler(ShouldQuiesceRecorder(promise: gotQueisceOnStreamPromise))
12581258
}.get()
12591259

1260-
clientConnectionChannel.pipeline.fireUserInboundEventTriggered(ChannelShouldQuiesceEvent())
1260+
clientConnectionChannel.parent!.pipeline.fireUserInboundEventTriggered(ChannelShouldQuiesceEvent())
12611261
try await gotQueisceOnStreamPromise.futureResult.get()
12621262

1263-
try await clientConnectionChannel.close()
1263+
try await clientConnectionChannel.closeFuture.get()
12641264
try await serverChannel.close()
12651265
}
12661266

Tests/H3IntegrationTests/HTTP3+NIOQUIC.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import class NIOQUIC.AsyncVerifier
2222
import class NIOQUIC.Authenticator
2323
import struct NIOQUIC.QUICConfiguration
2424
import class NIOQUIC.QUICHandler
25-
import struct NIOQUIC.QUICMetrics
2625
import struct NIOQUIC.QUICStreamCreator
2726

2827
typealias QUICHTTP3ConnectionHandler = HTTP3ConnectionHandler<QUICStreamCreator>
@@ -37,7 +36,6 @@ extension ChannelPipeline.SynchronousOperations {
3736
/// - configuration: The ``HTTP3ServerConfiguration``.
3837
/// - settings: The `HTTP3Settings` to use for all incoming connections.
3938
/// - quicConfiguration: The `QUICConfiguration` to be used.
40-
/// - metrics: The metrics.
4139
/// - logger: The logger.
4240
/// - inboundRequestStreamInitializer: Closure to run for each incoming stream. Must be synchronous.
4341
/// - Returns: A ``HTTP3ServerConnectionMultiplexer``. Use this to iterate incoming connections.
@@ -47,7 +45,6 @@ extension ChannelPipeline.SynchronousOperations {
4745
configuration: HTTP3ServerConfiguration = .defaults,
4846
settings: HTTP3Settings = .init(),
4947
quicConfiguration: QUICConfiguration,
50-
metrics: QUICMetrics? = nil,
5148
logger: Logger,
5249
inboundRequestStreamInitializer:
5350
@Sendable @escaping (HTTP3StreamInitializerParameters)
@@ -69,7 +66,6 @@ extension ChannelPipeline.SynchronousOperations {
6966
asyncVerifier: nil,
7067
authenticator: authenticator,
7168
logger: logger,
72-
metrics: metrics,
7369
inboundConnectionInitializer: { connectionChannel, streamCreator in
7470
connectionChannel.eventLoop.makeCompletedFuture {
7571
let loopBoundHandler: NIOLoopBoundBox<HTTP3ConnectionHandler<QUICStreamCreator>?> = .init(
@@ -114,7 +110,6 @@ extension ChannelPipeline.SynchronousOperations {
114110
/// - configuration: The ``HTTP3ClientConfiguration``.
115111
/// - settings: The `HTTP3Settings` to use for all outgoing connections.
116112
/// - quicConfiguration: The `QUICConfiguration` to be used.
117-
/// - metrics: The metrics.
118113
/// - logger: The logger.
119114
/// - internalInboundStreamInitializer: A closure which will be called for every incoming non-push stream.
120115
/// - Returns: A ``HTTP3ClientConnectionMultiplexer``. Use this to create outgoing connections.
@@ -124,7 +119,6 @@ extension ChannelPipeline.SynchronousOperations {
124119
configuration: HTTP3ClientConfiguration = .defaults,
125120
settings: HTTP3Settings = .init(),
126121
quicConfiguration: QUICConfiguration,
127-
metrics: QUICMetrics? = nil,
128122
logger: Logger,
129123
internalInboundStreamInitializer: (
130124
@Sendable (any Channel, QUICStreamID, HTTP3StreamType.Unidirectional) -> EventLoopFuture<Void>
@@ -148,7 +142,6 @@ extension ChannelPipeline.SynchronousOperations {
148142
asyncVerifier: asyncVerifier,
149143
authenticator: nil,
150144
logger: logger,
151-
metrics: metrics,
152145
inboundConnectionInitializer: { _, _ in
153146
fatalError()
154147
},
@@ -211,7 +204,6 @@ extension ChannelPipeline.SynchronousOperations {
211204
/// - configuration: The ``HTTP3ServerConfiguration``.
212205
/// - settings: The `HTTP3Settings` to use for all incoming connections.
213206
/// - quicConfiguration: The `QUICConfiguration` to be used.
214-
/// - metrics: The metrics.
215207
/// - logger: The logger.
216208
/// - inboundConnectionInitializer: Closure to run for each incoming connection.
217209
/// - inboundRequestStreamInitializer: Closure to run for each incoming request stream.
@@ -222,7 +214,6 @@ extension ChannelPipeline.SynchronousOperations {
222214
configuration: HTTP3ServerConfiguration = .defaults,
223215
settings: HTTP3Settings = .init(),
224216
quicConfiguration: QUICConfiguration,
225-
metrics: QUICMetrics? = nil,
226217
logger: Logger,
227218
inboundConnectionInitializer: @Sendable @escaping (any Channel) -> EventLoopFuture<Void>,
228219
inboundRequestStreamInitializer:
@@ -248,7 +239,6 @@ extension ChannelPipeline.SynchronousOperations {
248239
asyncVerifier: nil,
249240
authenticator: authenticator,
250241
logger: logger,
251-
metrics: metrics,
252242
inboundConnectionInitializer: { connectionChannel, streamCreator in
253243
connectionChannel.eventLoop.makeCompletedFuture {
254244
let h3Handler = HTTP3ConnectionHandler.server(

Tests/H3IntegrationTests/QUICConnectionCreator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ struct QUICConnectionCreator: HTTP3ConnectionCreator {
4040
}
4141
},
4242
inboundStreamInitializer: self.inboundStreamInitializer
43-
)
43+
).map { connectionChannel, _ in
44+
connectionChannel
45+
}
4446
}
4547
}

0 commit comments

Comments
 (0)