From 4f028cb62d1afd7fb5277e8e125cfacb937f5bb1 Mon Sep 17 00:00:00 2001 From: Tim <0xtimc@gmail.com> Date: Thu, 24 Aug 2023 12:25:53 +0100 Subject: [PATCH] Remove crash point --- Sources/Vapor/HTTP/Server/HTTPServer.swift | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/Sources/Vapor/HTTP/Server/HTTPServer.swift b/Sources/Vapor/HTTP/Server/HTTPServer.swift index ebf7041c1b..83636da226 100644 --- a/Sources/Vapor/HTTP/Server/HTTPServer.swift +++ b/Sources/Vapor/HTTP/Server/HTTPServer.swift @@ -357,7 +357,7 @@ private final class HTTPServerConnection: Sendable { } // Set the handlers that are applied to the accepted Channels - .childChannelInitializer { [weak application] channel in + .childChannelInitializer { [unowned application] channel in // add TLS handlers if configured if var tlsConfiguration = configuration.tlsConfiguration { // prioritize http/2 @@ -376,15 +376,11 @@ private final class HTTPServerConnection: Sendable { configuration.logger.error("Could not configure TLS: \(error)") return channel.close(mode: .all) } - let applicationBox = NIOLockedValueBox(application) return channel.pipeline.addHandler(tlsHandler).flatMap { _ in channel.configureHTTP2SecureUpgrade(h2ChannelConfigurator: { channel in channel.configureHTTP2Pipeline( mode: .server, inboundStreamInitializer: { channel in - guard let application = applicationBox.withLockedValue({ $0 }) else { - fatalError("Application has been deinitialized") - } return channel.pipeline.addVaporHTTP2Handlers( application: application, responder: responder, @@ -393,9 +389,6 @@ private final class HTTPServerConnection: Sendable { } ).map { _ in } }, http1ChannelConfigurator: { channel in - guard let application = applicationBox.withLockedValue({ $0 }) else { - fatalError("Application has been deinitialized") - } return channel.pipeline.addVaporHTTP1Handlers( application: application, responder: responder, @@ -408,7 +401,7 @@ private final class HTTPServerConnection: Sendable { fatalError("Plaintext HTTP/2 (h2c) not yet supported.") } return channel.pipeline.addVaporHTTP1Handlers( - application: application!, + application: application, responder: responder, configuration: configuration )