mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-25 22:26:42 +00:00
node: fix race condition on httpConfig access
This commit is contained in:
parent
72d92698a4
commit
50ccc0456c
1 changed files with 8 additions and 2 deletions
|
|
@ -70,7 +70,7 @@ type httpServer struct {
|
||||||
timeouts rpc.HTTPTimeouts
|
timeouts rpc.HTTPTimeouts
|
||||||
mux http.ServeMux // registered handlers go here
|
mux http.ServeMux // registered handlers go here
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.RWMutex
|
||||||
server *http.Server
|
server *http.Server
|
||||||
listener net.Listener // non-nil when server is running
|
listener net.Listener // non-nil when server is running
|
||||||
|
|
||||||
|
|
@ -207,7 +207,9 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if http-rpc is enabled, try to serve request
|
// if http-rpc is enabled, try to serve request
|
||||||
|
h.mu.RLock()
|
||||||
rpc := h.httpHandler.Load().(*rpcHandler)
|
rpc := h.httpHandler.Load().(*rpcHandler)
|
||||||
|
h.mu.RUnlock()
|
||||||
if rpc != nil {
|
if rpc != nil {
|
||||||
// First try to route in the mux.
|
// First try to route in the mux.
|
||||||
// Requests to a path below root are handled by the mux,
|
// Requests to a path below root are handled by the mux,
|
||||||
|
|
@ -219,7 +221,11 @@ func (h *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if checkPath(r, h.httpConfig.prefix) {
|
h.mu.RLock()
|
||||||
|
prefix := h.httpConfig.prefix
|
||||||
|
h.mu.RUnlock()
|
||||||
|
|
||||||
|
if checkPath(r, prefix) {
|
||||||
rpc.ServeHTTP(w, r)
|
rpc.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue