@@ -143,7 +143,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
143
143
// ! Work queue for handling longer requests off the event loop thread
144
144
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr };
145
145
// ! Handlers for (sub)paths
146
- static std::vector<HTTPPathHandler> pathHandlers;
146
+ static Mutex g_httppathhandlers_mutex;
147
+ static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY (g_httppathhandlers_mutex);
147
148
// ! Bound listening sockets
148
149
static std::vector<evhttp_bound_socket *> boundSockets;
149
150
@@ -244,6 +245,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
244
245
// Find registered handler for prefix
245
246
std::string strURI = hreq->GetURI ();
246
247
std::string path;
248
+ LOCK (g_httppathhandlers_mutex);
247
249
std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin ();
248
250
std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end ();
249
251
for (; i != iend; ++i) {
@@ -642,11 +644,13 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod() const
642
644
void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
643
645
{
644
646
LogPrint (BCLog::HTTP, " Registering HTTP handler for %s (exactmatch %d)\n " , prefix, exactMatch);
647
+ LOCK (g_httppathhandlers_mutex);
645
648
pathHandlers.push_back (HTTPPathHandler (prefix, exactMatch, handler));
646
649
}
647
650
648
651
void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
649
652
{
653
+ LOCK (g_httppathhandlers_mutex);
650
654
std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin ();
651
655
std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end ();
652
656
for (; i != iend; ++i)
0 commit comments