mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-27 09:21:43 +02:00
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.
This commit is contained in:
parent
2aaff4813c
commit
4e353cb618
@ -91,7 +91,7 @@ public:
|
|||||||
bool Enqueue(WorkItem* item)
|
bool Enqueue(WorkItem* item)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
if (queue.size() >= maxDepth) {
|
if (!running || queue.size() >= maxDepth) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
queue.emplace_back(std::unique_ptr<WorkItem>(item));
|
queue.emplace_back(std::unique_ptr<WorkItem>(item));
|
||||||
@ -107,7 +107,7 @@ public:
|
|||||||
WAIT_LOCK(cs, lock);
|
WAIT_LOCK(cs, lock);
|
||||||
while (running && queue.empty())
|
while (running && queue.empty())
|
||||||
cond.wait(lock);
|
cond.wait(lock);
|
||||||
if (!running)
|
if (!running && queue.empty())
|
||||||
break;
|
break;
|
||||||
i = std::move(queue.front());
|
i = std::move(queue.front());
|
||||||
queue.pop_front();
|
queue.pop_front();
|
||||||
@ -456,8 +456,6 @@ void StopHTTPServer()
|
|||||||
thread.join();
|
thread.join();
|
||||||
}
|
}
|
||||||
g_thread_http_workers.clear();
|
g_thread_http_workers.clear();
|
||||||
delete workQueue;
|
|
||||||
workQueue = nullptr;
|
|
||||||
}
|
}
|
||||||
// Unlisten sockets, these are what make the event loop running, which means
|
// 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.
|
// that after this and all connections are closed the event loop will quit.
|
||||||
@ -477,6 +475,10 @@ void StopHTTPServer()
|
|||||||
event_base_free(eventBase);
|
event_base_free(eventBase);
|
||||||
eventBase = nullptr;
|
eventBase = nullptr;
|
||||||
}
|
}
|
||||||
|
if (workQueue) {
|
||||||
|
delete workQueue;
|
||||||
|
workQueue = nullptr;
|
||||||
|
}
|
||||||
LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
|
LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user