There are no exceptions with run_async()
Somehow config errors are suppressed if the the server runs in async mode.
For example if i'm using a invalid .bindaddr("127.0.0"). If used with .run() i get a exception
(2024-09-03 14:35:15) [INFO ] Before Init
terminate called after throwing an instance of 'std::system_error'
what(): Invalid argument
(maybe not the greatest exception but good enough)
If i do the same with .run_async() it just hangs on wait_for_server_start() with out any exceptions.
Is that on purpose? Is there a way to wait or crash or maybe find out if the server crashed? Am i holding it wrong? :sweat_smile:
Full example:
#include <crow.h>
#include <chrono>
#include <thread>
int main(int /*ac*/, char ** /*av*/) {
crow::SimpleApp app;
CROW_ROUTE(app, "/")
([]() {
return "foo";
});
CROW_LOG_INFO << "Before Init";
// async example
auto f = app.bindaddr("127.0.0").port(8001).run_async();
app.wait_for_server_start();
// sync example
// app.bindaddr("127.0.0").port(8001).run();
CROW_LOG_INFO << "After Init";
using namespace std::chrono_literals;
std::this_thread::sleep_for(5s);
app.stop();
}
It fails in the constructor of the server due to asio::ip::address::from_string and throws an exception, therefore never a notification will be sent in run() and wait_for_server_start() waits forever.
In general I think a overload for wait_for_server_start(1s) with a overload for a timeout would be useful, i think there are a lot of cases where one would like to fail if it does not become ready in a certain time
Is there a way to achieve something with the current crow implementation?
I agree, a timeout would be generally useful. I would assume that it is easily possible.