Commit 2fd1b523 authored by Damien Mathieu's avatar Damien Mathieu Committed by Brad Fitzpatrick

net/http: lock the read-only mutex in shouldRedirect

Since that method uses 'mux.m', we need to lock the mutex to avoid data races.

Change-Id: I998448a6e482b5d6a1b24f3354bb824906e23172
GitHub-Last-Rev: 163a7d4942e793b328e05a7eb91f6d3fdc4ba12b
GitHub-Pull-Request: golang/go#23994
Reviewed-on: https://go-review.googlesource.com/96575Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent 1c9297c3
......@@ -581,6 +581,16 @@ func TestServeWithSlashRedirectForHostPatterns(t *testing.T) {
}
}
func TestShouldRedirectConcurrency(t *testing.T) {
setParallel(t)
defer afterTest(t)
mux := NewServeMux()
ts := httptest.NewServer(mux)
defer ts.Close()
mux.HandleFunc("/", func(w ResponseWriter, r *Request) {})
}
func BenchmarkServeMux(b *testing.B) {
type test struct {
......
......@@ -2223,6 +2223,9 @@ func (mux *ServeMux) redirectToPathSlash(host, path string, u *url.URL) (*url.UR
// path+"/". This should happen if a handler is registered for path+"/" but
// not path -- see comments at ServeMux.
func (mux *ServeMux) shouldRedirect(host, path string) bool {
mux.mu.RLock()
defer mux.mu.RUnlock()
p := []string{path, host + path}
for _, c := range p {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment