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.
This commit is contained in:
parent
e98a9eede2
commit
8d3f46ec39
1 changed files with 1 additions and 15 deletions
|
@ -22,7 +22,6 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <future>
|
|
||||||
|
|
||||||
#include <event2/thread.h>
|
#include <event2/thread.h>
|
||||||
#include <event2/buffer.h>
|
#include <event2/buffer.h>
|
||||||
|
@ -422,7 +421,6 @@ bool UpdateHTTPServerLogging(bool enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::thread threadHTTP;
|
std::thread threadHTTP;
|
||||||
std::future<bool> threadResult;
|
|
||||||
static std::vector<std::thread> g_thread_http_workers;
|
static std::vector<std::thread> g_thread_http_workers;
|
||||||
|
|
||||||
void StartHTTPServer()
|
void StartHTTPServer()
|
||||||
|
@ -430,9 +428,7 @@ void StartHTTPServer()
|
||||||
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
|
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
|
||||||
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
|
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
|
||||||
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
|
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
|
||||||
std::packaged_task<bool(event_base*)> task(ThreadHTTP);
|
threadHTTP = std::thread(ThreadHTTP, eventBase);
|
||||||
threadResult = task.get_future();
|
|
||||||
threadHTTP = std::thread(std::move(task), eventBase);
|
|
||||||
|
|
||||||
for (int i = 0; i < rpcThreads; i++) {
|
for (int i = 0; i < rpcThreads; i++) {
|
||||||
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue);
|
g_thread_http_workers.emplace_back(HTTPWorkQueueRun, workQueue);
|
||||||
|
@ -470,16 +466,6 @@ void StopHTTPServer()
|
||||||
boundSockets.clear();
|
boundSockets.clear();
|
||||||
if (eventBase) {
|
if (eventBase) {
|
||||||
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
|
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
|
||||||
// Give event loop a few seconds to exit (to send back last RPC responses), then break it
|
|
||||||
// Before this was solved with event_base_loopexit, but that didn't work as expected in
|
|
||||||
// at least libevent 2.0.21 and always introduced a delay. In libevent
|
|
||||||
// master that appears to be solved, so in the future that solution
|
|
||||||
// could be used again (if desirable).
|
|
||||||
// (see discussion in https://github.com/bitcoin/bitcoin/pull/6990)
|
|
||||||
if (threadResult.valid() && threadResult.wait_for(std::chrono::milliseconds(2000)) == std::future_status::timeout) {
|
|
||||||
LogPrintf("HTTP event loop did not exit within allotted time, sending loopbreak\n");
|
|
||||||
event_base_loopbreak(eventBase);
|
|
||||||
}
|
|
||||||
threadHTTP.join();
|
threadHTTP.join();
|
||||||
}
|
}
|
||||||
if (eventHTTP) {
|
if (eventHTTP) {
|
||||||
|
|
Loading…
Reference in a new issue