Skip to content

Commit 8d3f46e

Browse files
committed
http: Remove timeout to exit event loop
Let HTTP connections to timeout due to inactivity. Let all remaning connections finish sending the response and close.
1 parent e98a9ee commit 8d3f46e

File tree

1 file changed

+1
-15
lines changed

1 file changed

+1
-15
lines changed

src/httpserver.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <sys/types.h>
2323
#include <sys/stat.h>
2424
#include <signal.h>
25-
#include <future>
2625

2726
#include <event2/thread.h>
2827
#include <event2/buffer.h>
@@ -422,17 +421,14 @@ bool UpdateHTTPServerLogging(bool enable) {
422421
}
423422

424423
std::thread threadHTTP;
425-
std::future<bool> threadResult;
426424
static std::vector<std::thread> g_thread_http_workers;
427425

428426
void StartHTTPServer()
429427
{
430428
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
431429
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
432430
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
433-
std::packaged_task<bool(event_base*)> task(ThreadHTTP);
434-
threadResult = task.get_future();
435-
threadHTTP = std::thread(std::move(task), eventBase);
431+
threadHTTP = std::thread(ThreadHTTP, eventBase);
436432

437433
for (int i = 0; i < rpcThreads; i++) {
438434
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue);
@@ -470,16 +466,6 @@ void StopHTTPServer()
470466
boundSockets.clear();
471467
if (eventBase) {
472468
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
473-
// Give event loop a few seconds to exit (to send back last RPC responses), then break it
474-
// Before this was solved with event_base_loopexit, but that didn't work as expected in
475-
// at least libevent 2.0.21 and always introduced a delay. In libevent
476-
// master that appears to be solved, so in the future that solution
477-
// could be used again (if desirable).
478-
// (see discussion in https://github.com/bitcoin/bitcoin/pull/6990)
479-
if (threadResult.valid() && threadResult.wait_for(std::chrono::milliseconds(2000)) == std::future_status::timeout) {
480-
LogPrintf("HTTP event loop did not exit within allotted time, sending loopbreak\n");
481-
event_base_loopbreak(eventBase);
482-
}
483469
threadHTTP.join();
484470
}
485471
if (eventHTTP) {

0 commit comments

Comments
 (0)