Skip to content

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

@crontab

Description

@crontab

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, a33bb16

Swift & OS version

Swift 5.10
macOS 14.3.1 (23D60)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions