Skip to content

Commit 6b13580

Browse files
committed
http: Unlisten sockets after all workers quit
This (almost) move only ensures the event base loop doesn't exit before HTTP worker threads exit. This way events registered by HTTP workers are processed and not discarded.
1 parent 18e9685 commit 6b13580

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/httpserver.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,6 @@ void InterruptHTTPServer()
443443
{
444444
LogPrint(BCLog::HTTP, "Interrupting HTTP server\n");
445445
if (eventHTTP) {
446-
// Unlisten sockets
447-
for (evhttp_bound_socket *socket : boundSockets) {
448-
evhttp_del_accept_socket(eventHTTP, socket);
449-
}
450446
// Reject requests on current connections
451447
evhttp_set_gencb(eventHTTP, http_reject_request_cb, nullptr);
452448
}
@@ -466,6 +462,12 @@ void StopHTTPServer()
466462
delete workQueue;
467463
workQueue = nullptr;
468464
}
465+
// Unlisten sockets, these are what make the event loop running, which means
466+
// that after this and all connections are closed the event loop will quit.
467+
for (evhttp_bound_socket *socket : boundSockets) {
468+
evhttp_del_accept_socket(eventHTTP, socket);
469+
}
470+
boundSockets.clear();
469471
if (eventBase) {
470472
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
471473
// Exit the event loop as soon as there are no active events.

0 commit comments

Comments
 (0)