http: Release server before waiting for event base loop exit

This commit is contained in:
João Barbosa 2019-08-03 02:52:53 +01:00 committed by Fabian Jahr
parent 8c6d007c80
commit 660bdbf785
No known key found for this signature in database
GPG Key ID: F13D1E9D890798CD

View File

@ -486,15 +486,18 @@ void StopHTTPServer()
return g_requests.empty();
});
}
if (eventHTTP) {
// Schedule a callback to call evhttp_free in the event base thread, so
// that evhttp_free does not need to be called again after the handling
// of unfinished request connections that follows.
event_base_once(eventBase, -1, EV_TIMEOUT, [](evutil_socket_t, short, void*) {
evhttp_free(eventHTTP);
eventHTTP = nullptr;
}, nullptr, nullptr);
}
if (eventBase) {
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
if (g_thread_http.joinable()) g_thread_http.join();
}
if (eventHTTP) {
evhttp_free(eventHTTP);
eventHTTP = nullptr;
}
if (eventBase) {
event_base_free(eventBase);
eventBase = nullptr;
}