Skip to content

Commit

Permalink
Merge pull request #131 from orange-cloudfoundry/128-random-exception…
Browse files Browse the repository at this point in the history
…s-unregistering-routes

fix random exceptions when unregistering routes
  • Loading branch information
mdimiceli authored Jun 11, 2024
2 parents d6c45e1 + 2a90be7 commit 109f72b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions models/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,17 @@ func (rts Routes) Find(appIdOrPathOrName string) []*Route {
}

func (rts Routes) RegisterRoute(uri Uri, route *Route) {
if route == nil {
log.Warn("Cannot register nil route")
return
}
routekey := uri.RouteKey()
routes, ok := rts[routekey]

if ok {
found := false
for _, r := range routes {
if r.Equal(route) {
if route.Equal(r) {
found = true
break
}
Expand All @@ -141,12 +145,16 @@ func (rts Routes) RegisterRoute(uri Uri, route *Route) {
}

func (rts Routes) UnregisterRoute(uri Uri, route *Route) {
if route == nil {
log.Warn("Cannot unregister nil route")
return
}
routekey := uri.RouteKey()
routes, ok := rts[routekey]

if ok {
for idx, r := range routes {
if r.Equal(route) {
if route.Equal(r) {
log.Debugf("unregister route for uri %s and instance %s", string(uri), route.Tags.InstanceID)
// Trick for deleting an element from a slice
size := len(routes)
Expand Down

0 comments on commit 109f72b

Please sign in to comment.