Add support for swift-service-lifecycle#55
Add support for swift-service-lifecycle#55aryan-25 wants to merge 28 commits intoswift-server:mainfrom
Conversation
| public init( | ||
| server: Server, | ||
| serverHandler: Handler, | ||
| onGracefulShutdown gracefulShutdownHandler: @Sendable @escaping () -> Void = {} |
There was a problem hiding this comment.
Why do we need to let the user customize this? They can setup their own handler by wrapping this service if they wanted to.
There was a problem hiding this comment.
Agreed. I hadn't thought about this. I've removed the onGracefulShutdown argument now.
|
Looks very good—just two small additions, though:
Also, make sure you test all trait combinations: swift test --parallel --traits ServiceLifecycle
swift test --parallel --enable-all-traits
swift test --disable-default-traits
Thank you for the work. 🙏 |
The `configureHTTPServerPipeline` helper used in the `setupSecureUpgradeConnectionChildChannel` method originates from `NIOHTTP1`.
Package.swift
Outdated
| traits: [ | ||
| .trait(name: "SwiftConfiguration"), | ||
| .trait(name: "ServiceLifecycle"), | ||
| .default(enabledTraits: ["SwiftConfiguration"]), |
There was a problem hiding this comment.
It'd be nice if we could also enable the ServiceLifecycle trait by default.
There was a problem hiding this comment.
The ServiceLifecycle trait is now no longer needed; NIOHTTPServer depends on swift-service-lifecycle by default.
|
Following from #58, I've removed changes to the abstract server API in this PR and created a PR for those changes in the |
|
Based on some offline discussions, we won't be making any changes to the abstract All Users can use the new |
Motivation:
The
swift-service-lifecyclelibrary is commonly used for managing service lifetimes. We should adoptswift-service-lifecycleforNIOHTTPServer.Modifications:
Updated the child channel initializers for HTTP/1.1 and Secure Upgrade in
NIOHTTPServerto useswift-nio-extra'sServerQuiescingHelper. TheServerQuiescingHelperis added to the channel pipeline, and propagates aChannelShouldQuiesceEventupon graceful shutdown being triggered.For HTTP/1.1, the
HTTPServerPipelineHandlerhandler, which is contained in the pipeline, already handlesChannelShouldQuiesceEventevents.For HTTP/2, a
NIOHTTP2ServerConnectionManageris added to the pipeline. This connection manager reacts to aChannelShouldQuiesceEventand gracefully shuts down HTTP/2 connections.Updated
NIOHTTPServer'sserve(handler:)to handle graceful shutdown (usingswift-service-lifecycle'swithTaskCancellationOrGracefulShutdownHandlermethod).Result:
Support for
swift-service-lifecycleadded.