You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a controller constructor throws, the event loop appears to exit cleanly after merging PR #224 . However, when the program exits, a fatal error is triggered. Minimal reproduction using Drogon:
Create a Drogon project with a controller:
drogon_ctl create project CrashExample
cd CrashExample/controllers
drogon_ctl create controller ExceptionalController
Edit main.cc and controllers/ExceptionalController.h to read:
// ExceptionalController.h
#pragma once
#include <drogon/HttpSimpleController.h>
using namespace drogon;
class ExceptionalController : public drogon::HttpSimpleController<ExceptionalController>
{
public:
ExceptionalController() {
throw std::runtime_error("I'm exceptional, and therefore won't start. That should be fine.");
}
void asyncHandleHttpRequest(const HttpRequestPtr& req, std::function<void (const HttpResponsePtr &)> &&callback) override;
PATH_LIST_BEGIN
// list path definitions here;
//PATH_ADD("/path", "filter1", "filter2", HttpMethod1, HttpMethod2...);
PATH_ADD("/crash", Get);
PATH_LIST_END
};
//main.cc
#include <drogon/drogon.h>
int main() {
//Set HTTP listener address and port
drogon::app().addListener("0.0.0.0",80);
//Load config file
//drogon::app().loadConfigFile("../config.json");
//Run HTTP framework,the method will block in the internal event loop
try {
drogon::app().run();
} catch (std::exception & e) {
std::cout << "Caught exception \"" << e.what() << "\"... this is exiting.\n";
}
std::cout << "Press enter to exit...\n";
std::getchar();
return 0;
}
Build and run the app, press enter when prompted. Expected output:
20220926 06:35:01.622763 UTC 41933 WARN Exception thrown from event loop, rethrowing after running functions on quit - EventLoop.cc:243
20220926 06:35:01.623295 UTC 41933 WARN Rethrowing exception from event loop - EventLoop.cc:260
Caught exception "I'm exceptional, and therefore won't start. That should be fine."... this is exiting.
Press enter to exit...
Actual output:
20220926 06:35:01.622763 UTC 41933 WARN Exception thrown from event loop, rethrowing after running functions on quit - EventLoop.cc:243
20220926 06:35:01.623295 UTC 41933 WARN Rethrowing exception from event loop - EventLoop.cc:260
Caught exception "I'm exceptional, and therefore won't start. That should be fine."... this is exiting.
Press enter to exit...
20220926 06:35:05.766527 UTC 41933 FATAL It is forbidden to run loop on threads other than event-loop thread - EventLoop.cc:266
In other words, the event loop is still left in some illegal state. Note that the fatal error only appears after pressing enter.
The text was updated successfully, but these errors were encountered:
When a controller constructor throws, the event loop appears to exit cleanly after merging PR #224 . However, when the program exits, a fatal error is triggered. Minimal reproduction using Drogon:
Create a Drogon project with a controller:
Edit
main.cc
andcontrollers/ExceptionalController.h
to read:Build and run the app, press enter when prompted. Expected output:
Actual output:
In other words, the event loop is still left in some illegal state. Note that the fatal error only appears after pressing enter.
The text was updated successfully, but these errors were encountered: