Skip to content

Commit

Permalink
server: remove safeServeMux
Browse files Browse the repository at this point in the history
`safeServeMux` was a wrapper to provide proper locking around
`http.ServeMux` because in go1.10 and below, calls to `Handle` and
`ServeHTTP` could race with each other.

We don't need it anymore, see cockroachdb#29230.

Release note: None
  • Loading branch information
aayushshah15 committed Jul 24, 2020
1 parent 81cc169 commit 609fda3
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 87 deletions.
64 changes: 0 additions & 64 deletions pkg/server/servemux_test.go

This file was deleted.

24 changes: 1 addition & 23 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,14 @@ var (
)
)

// TODO(peter): Until go1.11, ServeMux.ServeHTTP was not safe to call
// concurrently with ServeMux.Handle. So we provide our own wrapper with proper
// locking. Slightly less efficient because it locks unnecessarily, but
// safe. See TestServeMuxConcurrency. Should remove once we've upgraded to
// go1.11.
type safeServeMux struct {
mu syncutil.RWMutex
mux http.ServeMux
}

func (mux *safeServeMux) Handle(pattern string, handler http.Handler) {
mux.mu.Lock()
mux.mux.Handle(pattern, handler)
mux.mu.Unlock()
}

func (mux *safeServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
mux.mu.RLock()
mux.mux.ServeHTTP(w, r)
mux.mu.RUnlock()
}

// Server is the cockroach server node.
type Server struct {
// The following fields are populated in NewServer.

nodeIDContainer *base.NodeIDContainer
cfg Config
st *cluster.Settings
mux safeServeMux
mux http.ServeMux
clock *hlc.Clock
rpcContext *rpc.Context
// The gRPC server on which the different RPC handlers will be registered.
Expand Down

0 comments on commit 609fda3

Please sign in to comment.