mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-15 20:29:59 +01:00
Merge bitcoin/bitcoin#26033: [23.x] Prevent data race for pathHandlers
38d4601fe8
Prevent data race for `pathHandlers` (Hennadii Stepanov) Pull request description: Backport of https://github.com/bitcoin/bitcoin/pull/25983 to the 23.x branch. ACKs for top commit: dergoegge: ACK38d4601fe8
Tree-SHA512: b235d6d2cb374baf1b54c09f4cd2feca7b6c1588d081532e987fd5def8ed0dee4b8255112b130a77aca633ec6a63cfd81f215b2e7a403c213eb6048a54774d26
This commit is contained in:
commit
40b69fb06e
1 changed files with 5 additions and 1 deletions
|
@ -143,7 +143,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
|
||||||
//! Work queue for handling longer requests off the event loop thread
|
//! Work queue for handling longer requests off the event loop thread
|
||||||
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr};
|
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr};
|
||||||
//! Handlers for (sub)paths
|
//! Handlers for (sub)paths
|
||||||
static std::vector<HTTPPathHandler> pathHandlers;
|
static Mutex g_httppathhandlers_mutex;
|
||||||
|
static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY(g_httppathhandlers_mutex);
|
||||||
//! Bound listening sockets
|
//! Bound listening sockets
|
||||||
static std::vector<evhttp_bound_socket *> boundSockets;
|
static std::vector<evhttp_bound_socket *> boundSockets;
|
||||||
|
|
||||||
|
@ -244,6 +245,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
|
||||||
// Find registered handler for prefix
|
// Find registered handler for prefix
|
||||||
std::string strURI = hreq->GetURI();
|
std::string strURI = hreq->GetURI();
|
||||||
std::string path;
|
std::string path;
|
||||||
|
LOCK(g_httppathhandlers_mutex);
|
||||||
std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
|
std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin();
|
||||||
std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
|
std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end();
|
||||||
for (; i != iend; ++i) {
|
for (; i != iend; ++i) {
|
||||||
|
@ -642,11 +644,13 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() const
|
||||||
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
|
void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
|
||||||
{
|
{
|
||||||
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
|
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
|
||||||
|
LOCK(g_httppathhandlers_mutex);
|
||||||
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
|
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
|
void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
|
||||||
{
|
{
|
||||||
|
LOCK(g_httppathhandlers_mutex);
|
||||||
std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin();
|
std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin();
|
||||||
std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end();
|
std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end();
|
||||||
for (; i != iend; ++i)
|
for (; i != iend; ++i)
|
||||||
|
|
Loading…
Add table
Reference in a new issue