drogon icon indicating copy to clipboard operation
drogon copied to clipboard

HttpRequest::sendRequest() hangs forever if it is called after app().quit()

Open Demilivor opened this issue 7 months ago • 1 comments

Describe the bug HttpRequest::sendRequest() hangs forever if it is called after app().quit();

To Reproduce Run this unit test:

#include <drogon/drogon.h>
#include <gtest/gtest.h>

#include <chrono>
#include <thread>

using namespace drogon;

namespace app
{

TEST(DrogonHttpClientAppQuitRace, TestDrogonHttpFramework)
{
    app().getLoop()->queueInLoop([]() { app().quit(); });

    auto client = HttpClient::newHttpClient("http://www.DoesNotMatter.com");
    std::jthread application_thread(
        [client]()
        {
            // Simulate real application work in some dedicated thread.
            std::this_thread::sleep_for(std::chrono::milliseconds(2000));

            // User application does not know that application is going to quit (quit maybe called right now).
            // if (app().isRunning()) check does not help, because quiting may be called right between app().isRunning() and client->sendRequest()
            auto req = HttpRequest::newHttpRequest();
            // I would expect have an exception (Drogon application is stopped)
            // Or stop at least get the error after 1 second timeout,
            // But actual result is hanging forever.
            client->sendRequest(req, 1.0);
        });
    app().run();
    application_thread.join();
}

}

Expected behavior client->sendRequest should throw an exception, or at least a timeout should happen.

Demilivor avatar Jun 26 '25 00:06 Demilivor

Note: I ran this test on Ubuntu:

lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.4 LTS
Release:        22.04
Codename:       jammy

Demilivor avatar Jun 26 '25 00:06 Demilivor