diff options
author | João Barbosa <joao.paulo.barbosa@gmail.com> | 2020-05-21 18:12:49 +0100 |
---|---|---|
committer | João Barbosa <joao.paulo.barbosa@gmail.com> | 2020-07-09 20:12:53 +0100 |
commit | 4e353cb618745cdb5d98e58e7dcd400ded01299a (patch) | |
tree | d65dedd8ea2bd3fd5c84b275f9b9d33c7626c53b /src/httpserver.cpp | |
parent | 2aaff4813cc340764c99846513d58fc3553fcb6a (diff) |
http: Release work queue after event base finish
This fixes a race between http_request_cb and StopHTTPServer where
the work queue is used after release.
Diffstat (limited to 'src/httpserver.cpp')
-rw-r--r-- | src/httpserver.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 1e5ea2de83..0bc46a4d03 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -91,7 +91,7 @@ public: bool Enqueue(WorkItem* item) { LOCK(cs); - if (queue.size() >= maxDepth) { + if (!running || queue.size() >= maxDepth) { return false; } queue.emplace_back(std::unique_ptr<WorkItem>(item)); @@ -107,7 +107,7 @@ public: WAIT_LOCK(cs, lock); while (running && queue.empty()) cond.wait(lock); - if (!running) + if (!running && queue.empty()) break; i = std::move(queue.front()); queue.pop_front(); @@ -456,8 +456,6 @@ void StopHTTPServer() thread.join(); } g_thread_http_workers.clear(); - delete workQueue; - workQueue = nullptr; } // Unlisten sockets, these are what make the event loop running, which means // that after this and all connections are closed the event loop will quit. @@ -477,6 +475,10 @@ void StopHTTPServer() event_base_free(eventBase); eventBase = nullptr; } + if (workQueue) { + delete workQueue; + workQueue = nullptr; + } LogPrint(BCLog::HTTP, "Stopped HTTP server\n"); } |