-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] runtime error in (*routeRegexp).Match #749
Comments
The test below- while it doesn't yet replicate this- when it's run with func TestConcurrentRouteMatchingAndModification(t *testing.T) {
r := NewRouter()
var wg sync.WaitGroup
concurrency := 1000
panicChan := make(chan interface{}, concurrency)
for i := 0; i < concurrency; i++ {
wg.Add(1)
go func(i int) {
defer func() {
if re := recover(); re != nil {
panicChan <- re
}
}()
defer wg.Done()
if i%2 == 0 {
r.HandleFunc(
fmt.Sprintf("/test/%d/{id:[0-9]+}", i),
func(w http.ResponseWriter, r *http.Request) {
defer func() {
if perr := recover(); perr != nil {
t.Fatalf("%v", perr)
}
}()
// t.Logf("request: %s", r.RequestURI)
},
)
} else {
req := httptest.NewRequest(
"GET",
fmt.Sprintf("/test/%d/123", i-1),
nil,
)
w := httptest.NewRecorder()
r.ServeHTTP(w, req)
}
}(i)
}
wg.Wait()
close(panicChan)
for p := range panicChan {
t.Errorf("Panic occurred: %v", p)
}
} Data races:
I was able to eliminate the races by adding mutexes to:
The race at least seems to be from functions being able to concurrently read/copy/modify |
@arcward The mux does not support modifying routes concurrently with serving requests. Applications should assume this restriction following Go conventions (concurrency is not supported unless explicitly stated). Perhaps the documentation should be updated to explicitly state the restriction. @streamer45 Does your application modify the routes concurrently with serving requests? Try running the application with the Data Race Detector to see if the detector reports any problems. |
@hulkingshtick Our full test suite runs in |
The panic indicates that the field routeRegexp.regexp == nil. I cannot find a code path that will set the field to nil, even in the presence of a data race. I am leaving this comment in case it helps another investigator. |
Very interesting thanks for sharing. If I am able to get around to this I’ll test it out |
@hulkingshtick Entendu, and for normal usage, absolutely. After the nil I saw 'sentry' and 'automation' and suspected it may be something that (maybe only) happens in test cases. I honed in on |
Is there an existing issue for this?
Current Behavior
Code panics
Expected Behavior
Not to panic but return an error
Steps To Reproduce
It's a sporadic issue we spotted through automation (Sentry) so hard to tell how it could be reproduced but somehow the regexp pointer is
nil
when the code attempts to match.Anything else?
Stacktrace
The text was updated successfully, but these errors were encountered: