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 <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2023-12-06 11:20:47 -05:00
parent 424ae36046
commit 1931a1bdc7

View file

@ -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)
}