Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are no exceptions with run_async() #885

Open
fliiiix opened this issue Sep 3, 2024 · 3 comments
Open

There are no exceptions with run_async() #885

fliiiix opened this issue Sep 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@fliiiix
Copy link
Contributor

fliiiix commented Sep 3, 2024

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? 😅

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();
}
@gittiver gittiver added the bug Something isn't working label Sep 3, 2024
@gittiver
Copy link
Member

gittiver commented Sep 3, 2024

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.

@fliiiix
Copy link
Contributor Author

fliiiix commented Sep 4, 2024

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?

@gittiver
Copy link
Member

gittiver commented Sep 4, 2024

I agree, a timeout would be generally useful. I would assume that it is easily possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants