mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
Merge bitcoin/bitcoin#19033: http: Release work queue after event base finish
4e353cb618
http: Release work queue after event base finish (João Barbosa) Pull request description: This fixes a race between `http_request_cb` and `StopHTTPServer` where the work queue is used after release. Fixes #18856. ACKs for top commit: fjahr: Code review ACK4e353cb618
achow101: ACK4e353cb618
LarryRuane: ACK4e353cb618
hebasto: ACK4e353cb618
, tested (rebased on top of master9313c4e6aa
) on Linux Mint 20.1 (x86_64) using MarcoFalke's [patch](https://github.com/bitcoin/bitcoin/pull/19033#issuecomment-640106647), including different `-rpcthreads`/`-rpcworkqueue` cases. The bug is fixed. The code is correct. Tree-SHA512: 185d2a9744d0d5134d782bf321ac9958ba17b11a5b3d70b4897c8243e6b146dfd3f23c57aef8e10ae9484374120b64389c1949a9cf0a21dccc47ffc934c20930
This commit is contained in:
commit
6a67366fdc
1 changed files with 6 additions and 4 deletions
|
@ -83,7 +83,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));
|
||||||
|
@ -99,7 +99,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();
|
||||||
|
@ -448,8 +448,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.
|
||||||
|
@ -469,6 +467,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…
Add table
Reference in a new issue