Skip to content

Event loop not ending for thread #109

@dreadsfun

Description

@dreadsfun

Hi

Using WSL with Ubuntu, GCC 11.1.0 and CMake to build my project with lithium I have the following issue
In my main I have:

http_api root;
lemw::api::auth auth(root);
http_serve(root, 8080);

auth registers an empty post handler on /auth/login

void auth::login(http_request& request, http_response& response) {
  response.write_json(s::success = true);
}

The server starts fine, and if I don't call the login endpoint, it also stops fine with ctrl+C, (sending SIGTERM):

Starting lithium::http_server on port 8080
^CThe server will shutdown...
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP

However, If I call the login endpoint before trying to exit, one of the threads (the one that handled the request) gets stuck:

Starting lithium::http_server on port 8080
^CThe server will shutdown...
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
Killed

From the 6 threads only 5 reaches end of event loop, then it only stops with sending SIGKILL to the main thread
Without the kill signal, the server actually continues to serve requests with that one thread:

(Here I have spdlog set up to see what's happening, but the same thing happens without any extra code)

[01:38:45] [I] [T9653] Start logging
Starting lithium::http_server on port 8080
[01:38:51] [D] [T9664] login request username password
^CThe server will shutdown...
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
END OF EVENT LOOP
[01:40:29] [D] [T9664] login request username password
[01:40:33] [D] [T9664] login request username password
^CThe server will shutdown...
[01:43:22] [D] [T9664] login request username password
^CThe server will shutdown...
^CThe server will shutdown...
^CThe server will shutdown...
Killed

What could be the reason for this? Am I missing something to properly shut the server down?

Any help or suggestion is greatly appreciated
Thank you in advance!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions