@@ -142,7 +142,8 @@ static std::vector<CSubNet> rpc_allow_subnets;
142142// ! Work queue for handling longer requests off the event loop thread
143143static std::unique_ptr<WorkQueue<HTTPClosure>> g_work_queue{nullptr };
144144// ! 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);
146147// ! Bound listening sockets
147148static std::vector<evhttp_bound_socket *> boundSockets;
148149
@@ -243,6 +244,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
243244 // Find registered handler for prefix
244245 std::string strURI = hreq->GetURI ();
245246 std::string path;
247+ LOCK (g_httppathhandlers_mutex);
246248 std::vector<HTTPPathHandler>::const_iterator i = pathHandlers.begin ();
247249 std::vector<HTTPPathHandler>::const_iterator iend = pathHandlers.end ();
248250 for (; i != iend; ++i) {
@@ -674,11 +676,13 @@ std::optional<std::string> GetQueryParameterFromUri(const char* uri, const std::
674676void RegisterHTTPHandler (const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
675677{
676678 LogPrint (BCLog::HTTP, " Registering HTTP handler for %s (exactmatch %d)\n " , prefix, exactMatch);
679+ LOCK (g_httppathhandlers_mutex);
677680 pathHandlers.push_back (HTTPPathHandler (prefix, exactMatch, handler));
678681}
679682
680683void UnregisterHTTPHandler (const std::string &prefix, bool exactMatch)
681684{
685+ LOCK (g_httppathhandlers_mutex);
682686 std::vector<HTTPPathHandler>::iterator i = pathHandlers.begin ();
683687 std::vector<HTTPPathHandler>::iterator iend = pathHandlers.end ();
684688 for (; i != iend; ++i)
0 commit comments