Skip to content

Commit f8f1ecd

Browse files
authored
Merge pull request #718 from openziti/fix-er-conn-race-condition-leak
Fix ER connection race condition leak. Fixes #717
2 parents 1180829 + baaaa95 commit f8f1ecd

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ziti/ziti.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,13 @@ func (context *ContextImpl) Sessions() ([]*rest_model.SessionDetail, error) {
486486

487487
func (context *ContextImpl) OnClose(routerConn edge.RouterConn) {
488488
logrus.Debugf("connection to router [%s] was closed", routerConn.Key())
489-
context.Emit(EventRouterDisconnected, routerConn.GetRouterName(), routerConn.Key())
490-
context.routerConnections.Remove(routerConn.Key())
489+
removed := context.routerConnections.RemoveCb(routerConn.Key(), func(key string, v edge.RouterConn, exists bool) bool {
490+
return exists && v == routerConn
491+
})
492+
493+
if removed {
494+
context.Emit(EventRouterDisconnected, routerConn.GetRouterName(), routerConn.Key())
495+
}
491496
}
492497

493498
func (context *ContextImpl) processServiceUpdates(services []*rest_model.ServiceDetail) {
@@ -1469,8 +1474,6 @@ func (context *ContextImpl) connectEdgeRouter(routerName, ingressUrl string) *ed
14691474

14701475
logger.Debugf("connected to %s", ingressUrl)
14711476

1472-
context.Emit(EventRouterConnected, edgeConn.GetRouterName(), edgeConn.Key())
1473-
14741477
useConn := context.routerConnections.Upsert(ingressUrl, edgeConn,
14751478
func(exist bool, oldV edge.RouterConn, newV edge.RouterConn) edge.RouterConn {
14761479
if exist { // use the routerConnection already in the map, close new one
@@ -1511,6 +1514,10 @@ func (context *ContextImpl) connectEdgeRouter(routerName, ingressUrl string) *ed
15111514
return newV
15121515
})
15131516

1517+
if useConn == edgeConn {
1518+
context.Emit(EventRouterConnected, edgeConn.GetRouterName(), edgeConn.Key())
1519+
}
1520+
15141521
return &edgeRouterConnResult{
15151522
routerUrl: ingressUrl,
15161523
routerName: routerName,

0 commit comments

Comments
 (0)