Skip to content

Commit

Permalink
refactor: fix mutex deadlock in addRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
luk3skyw4lker committed Jul 16, 2024
1 parent 141f858 commit 9d736d6
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ func (app *App) register(methods []string, pathRaw string, group *Group, handler
}

func (app *App) addRoute(method string, route *Route, isMounted ...bool) {
app.mutex.Lock()
defer app.mutex.Unlock()

// Check mounted routes
var mounted bool
if len(isMounted) > 0 {
Expand All @@ -400,12 +403,10 @@ func (app *App) addRoute(method string, route *Route, isMounted ...bool) {

// Execute onRoute hooks & change latestRoute if not adding mounted route
if !mounted {
app.mutex.Lock()
app.latestRoute = route
if err := app.hooks.executeOnRouteHooks(*route); err != nil {
panic(err)
}
app.mutex.Unlock()
}
}

Expand Down

0 comments on commit 9d736d6

Please sign in to comment.