@@ -486,8 +486,13 @@ func (context *ContextImpl) Sessions() ([]*rest_model.SessionDetail, error) {
486
486
487
487
func (context * ContextImpl ) OnClose (routerConn edge.RouterConn ) {
488
488
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
+ }
491
496
}
492
497
493
498
func (context * ContextImpl ) processServiceUpdates (services []* rest_model.ServiceDetail ) {
@@ -1469,8 +1474,6 @@ func (context *ContextImpl) connectEdgeRouter(routerName, ingressUrl string) *ed
1469
1474
1470
1475
logger .Debugf ("connected to %s" , ingressUrl )
1471
1476
1472
- context .Emit (EventRouterConnected , edgeConn .GetRouterName (), edgeConn .Key ())
1473
-
1474
1477
useConn := context .routerConnections .Upsert (ingressUrl , edgeConn ,
1475
1478
func (exist bool , oldV edge.RouterConn , newV edge.RouterConn ) edge.RouterConn {
1476
1479
if exist { // use the routerConnection already in the map, close new one
@@ -1511,6 +1514,10 @@ func (context *ContextImpl) connectEdgeRouter(routerName, ingressUrl string) *ed
1511
1514
return newV
1512
1515
})
1513
1516
1517
+ if useConn == edgeConn {
1518
+ context .Emit (EventRouterConnected , edgeConn .GetRouterName (), edgeConn .Key ())
1519
+ }
1520
+
1514
1521
return & edgeRouterConnResult {
1515
1522
routerUrl : ingressUrl ,
1516
1523
routerName : routerName ,
0 commit comments