From 1931a1bdc74e7676431561670d5a85bca5554e6d Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Wed, 6 Dec 2023 11:20:47 -0500 Subject: [PATCH] libnetwork/diagnostic: lock mutex in help handler Acquire the mutex in the help handler to synchronize access to the handlers map. While a trivial issue---a panic in the request handler if the node joins a swarm at just the right time, which would only result in an HTTP 500 response---it is also a trivial race condition to fix. Signed-off-by: Cory Snider --- libnetwork/diagnostic/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libnetwork/diagnostic/server.go b/libnetwork/diagnostic/server.go index 966201c448..c773b96918 100644 --- a/libnetwork/diagnostic/server.go +++ b/libnetwork/diagnostic/server.go @@ -147,9 +147,11 @@ func (s *Server) help(w http.ResponseWriter, r *http.Request) { }).Info("help done") var result string + s.mu.Lock() for path := range s.handlers { result += fmt.Sprintf("%s\n", path) } + s.mu.Unlock() _, _ = HTTPReply(w, CommandSucceed(&StringCmd{Info: result}), jsonOutput) }