Skip to content

Commit 941f500

Browse files
authored
Add a handler for managing connections on the server (#1762)
Motivation: Servers must manage connections created by clients. Part of this is gracefully closing connections (by sending GOAWAY frames and ratcheting down the last stream ID) in response to various conditions: the client sending too many pings, the connection being idle too long, the connection existing for longer than some configured limit, etc. A previous change added a state machine which handles much of this behaviour. This change adds a channel handler which builds on top of that state machine. Modifications: - Add a channel handler for managing connections on the server. Result: We have a handler in place which can manage connections on the server.
1 parent 1e36bdc commit 941f500

File tree

7 files changed

+955
-28
lines changed

7 files changed

+955
-28
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,10 @@ extension Target {
306306
static let grpcHTTP2CoreTests: Target = .testTarget(
307307
name: "GRPCHTTP2CoreTests",
308308
dependencies: [
309-
.grpcHTTP2Core
309+
.grpcHTTP2Core,
310+
.nioCore,
311+
.nioHTTP2,
312+
.nioEmbedded,
310313
]
311314
)
312315

Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionHandler.swift

Lines changed: 0 additions & 19 deletions
This file was deleted.

Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionHandler+StateMachine.swift renamed to Sources/GRPCHTTP2Core/Server/Connection/ServerConnectionManagementHandler+StateMachine.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import NIOCore
1818
import NIOHTTP2
1919

20-
extension ServerConnectionHandler {
20+
extension ServerConnectionManagementHandler {
2121
/// Tracks the state of TCP connections at the server.
2222
///
2323
/// The state machine manages the state for the graceful shutdown procedure as well as policing
@@ -248,7 +248,7 @@ extension ServerConnectionHandler {
248248
}
249249
}
250250

251-
extension ServerConnectionHandler.StateMachine {
251+
extension ServerConnectionManagementHandler.StateMachine {
252252
fileprivate struct KeepAlive {
253253
/// Allow the client to send keep alive pings when there are no active calls.
254254
private let allowWithoutCalls: Bool
@@ -267,8 +267,7 @@ extension ServerConnectionHandler.StateMachine {
267267
/// alive (a low number of strikes is therefore expected and okay).
268268
private var pingStrikes: Int
269269

270-
/// The last time a valid ping happened. This may be in the distant past if there is no such
271-
/// time (for example the connection is new and there are no active calls).
270+
/// The last time a valid ping happened.
272271
///
273272
/// Note: `distantPast` isn't used to indicate no previous valid ping as `NIODeadline` uses
274273
/// the monotonic clock on Linux which uses an undefined starting point and in some cases isn't
@@ -320,7 +319,7 @@ extension ServerConnectionHandler.StateMachine {
320319
}
321320
}
322321

323-
extension ServerConnectionHandler.StateMachine {
322+
extension ServerConnectionManagementHandler.StateMachine {
324323
fileprivate enum State {
325324
/// The connection is active.
326325
struct Active {

0 commit comments

Comments
 (0)