소스 검색

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>
Cory Snider 1 년 전
부모
커밋
1931a1bdc7
1개의 변경된 파일2개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      libnetwork/diagnostic/server.go

+ 2 - 0
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)
 }