@@ -142,7 +142,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
142
142
// ! Work queue for handling longer requests off the event loop thread
143
143
static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr };
144
144
// ! Handlers for (sub)paths
145
- static std::vector<HTTPPathHandler> pathHandlers;
145
+ static GlobalMutex g_httppathhandlers_mutex;
146
+ static std::vector<HTTPPathHandler> pathHandlers GUARDED_BY (g_httppathhandlers_mutex);
146
147
// ! Bound listening sockets
147
148
static std::vector<evhttp_bound_socket *> boundSockets;
148
149
@@ -243,6 +244,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
243
244
// Find registered handler for prefix
244
245
std::string strURI = hreq->GetURI ();
245
246
std::string path;
247
+ LOCK (g_httppathhandlers_mutex);
246
248
std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin ();
247
249
std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end ();
248
250
for (; i != iend; ++i) {
@@ -674,11 +676,13 @@ std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::
674
676
void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
675
677
{
676
678
LogPrint (BCLog::HTTP, " Registering HTTP handler for %s (exactmatch %d)\n " , prefix, exactMatch);
679
+ LOCK (g_httppathhandlers_mutex);
677
680
pathHandlers.push_back (HTTPPathHandler (prefix, exactMatch, handler));
678
681
}
679
682
680
683
void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
681
684
{
685
+ LOCK (g_httppathhandlers_mutex);
682
686
std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin ();
683
687
std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end ();
684
688
for (; i != iend; ++i)
0 commit comments