swift-nio-extras icon indicating copy to clipboard operation
swift-nio-extras copied to clipboard

HTTPServerWithQuiescingDemo prints an error if the main code is wrapped in a function

Open crontab opened this issue 11 months ago • 3 comments

Expected behavior

The demo should be able to shutdown gracefully on SIGINT.

Actual behavior

If the top-level code is wrapped in a function like so:

func run() throws {
    // main top-level code, unchanged
}

try run()

then upon receiving SIGINT the app prints:

ERROR: Cannot schedule tasks on an EventLoop that has already shut down.
    This will be upgraded to a forced crash in future SwiftNIO versions.

and seems to shut down everything and exit normally.

This is a pretty big inconvenience as in any more or less complex project the code that bootstraps the server will most likely be in a function.

The main suspicion is that some destructor is called at the end of run() that tries to use an EventLoop. No idea which object in the main code that might be. Any help would be greatly appreciated!

SwiftNIO-Extras version/commit hash

Current HEAD, a33bb16e794432ffc1e6de49d2e7f9478689a6ac

Swift & OS version

Swift 5.10 macOS 14.3.1 (23D60)

crontab avatar Mar 11 '24 20:03 crontab