Since that method uses `mux.m`, we need to lock the mutex to avoid data races.
Fixes #27129
Change-Id: I998448a6e482b5d6a1b24f3354bb824906e23172
Reviewed-on: https://go-review.googlesource.com/95775
Reviewed-by: Andrew Bonventre <andybons@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
}
}
+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 {
// 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 {