CrowCpp / Crow

A Fast and Easy to use microframework for the web.
https://crowcpp.org
Other
3.3k stars 363 forks source link

How can I release sources before exit #938

Open xstar2091 opened 1 week ago

xstar2091 commented 1 week ago

made a http server var CrowCpp. It crashed when exit the server by Ctrl+C if handler was already running. I tried to stop the handler used atexit and signal like this

#include <csignal>
#include <crow.h>

void OnExitHandler()
{
// release sources here
}

void OnSignalHandler(int signum)
{
    if (signum == SIGINT)
    {
        OnExitHandler();
    }
}

int main()
{
    std::atexit(&OnExitHandler);
    signal(SIGINT, &OnSignalHandler);

    crow::SimpleApp app;

    // http server here

    app.port(conf->server().port)
       .multithreaded()
       .loglevel(crow::LogLevel::Warning)
       .run();
    return 0;
}

But it did not work. SIGINT signal was not processed in my handler function "OnSignalHandler".

So, How can I stop the running handler and release the sources before exit?

xstar2091 commented 2 days ago

My pr is blocked. The tests failed unfortunately. I don't have a Mac or Windows device, so there's no way to troubleshoot these errors.

The test was canceld on Windows because of the "Prepare dependencies" went error. The test failed on task_timer on Macos-13. I dont have mac to roubleshoot the error and I think it is not related to the signal fix code.

gittiver commented 2 days ago

its a timing issue on osx, i restarted the job. I already have a bug and branch for it but not done yet.