drogonframework / drogonframework/drogon
Failing gracefully on exception from controller construction
- Dominant language
- C++
- Stars
- 14.3k
- Forks
- 1.4k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 15
Description
When a constructor of an HttpController throws, and the exception propagates through `drogon::app().run()` to `main()` and is caught there, it appears impossible to exit the program gracefully, since the assert on `trantor/net/EventLoop.cc:115` in `EventLoop::~Eventloop()` triggers on exit. Looking at the source code, it appears that there is no easy workaround, since `looping_` in the trantor event loop is not handled exception safely.
My use case for throwing in the constructor of a controller is that there are some settings (currently loaded from `config.json`) which, if misconfigured, may prevent the service from doing its work at all. In that case, I believe it's better for the service to exit on startup and let the admin know to fix the configuration, rather than running a non-functional service.
There should be a way to exit gracefully when exceptions are thrown in controller constructors.
Contributor guide
Assessment
This issue has not been assessed yet.