drogonframework / drogonframework/drogon

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

Open
#2,340 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
14.3k
Forks
1.4k
Avg merge
1d 12h
Merged PRs (30d)
15

Description

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

**To Reproduce**
Run this unit test:

```cpp
#include
#include

#include
#include

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.

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.