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) {