drogonframework / drogonframework/drogon

Failing gracefully on exception from controller construction

Open
#1,157 3 comments 0 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.