From f60cb3c05a0c381bd77f667a7127832de61c577e Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Tue, 28 Nov 2023 11:20:29 +0100 Subject: [PATCH] Rework shutdown procedure --- Sources/App/configure.swift | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Sources/App/configure.swift b/Sources/App/configure.swift index 6021e33..537c949 100755 --- a/Sources/App/configure.swift +++ b/Sources/App/configure.swift @@ -58,21 +58,15 @@ public func configure(_ app: Application) throws { } log("[\(df.string(from: Date()))] Server started") - - // Gracefully shut down by closing potentially open socket - // Must be done after app is running, otherwise error is thrown - DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .seconds(5)) { - _ = app.server.onShutdown.always { _ in - print("[\(df.string(from: Date()))] Server shutdown") - asyncScheduler.schedule { - await deviceManager.removeDeviceConnection() - } - } - } } public func shutdown() { - try? asyncScheduler.syncShutdownGracefully() + print("[\(df.string(from: Date()))] Server shutdown") + asyncScheduler.schedule { + // Gracefully shut down by closing potentially open socket + await deviceManager.removeDeviceConnection() + try? await asyncScheduler.shutdownGracefully() + } } private func loadKeys(at url: URL) throws -> (deviceKey: Data, remoteKey: Data) {