@@ -65,13 +65,9 @@ func Clean() {
6565 }
6666 }
6767
68- for _ , tunnel := range Tunnels .Connections {
69- if now .Sub (tunnel .LastConnection ).Seconds () > 266 {
70- closeTunnel (tunnel )
71- continue
72- }
73-
74- if tunnel .SshClient == nil {
68+ for key , tunnel := range Tunnels .Connections {
69+ if now .Sub (tunnel .LastConnection ).Seconds () > 266 || tunnel .SshClient == nil {
70+ closeTunnel (tunnel , key )
7571 continue
7672 }
7773
@@ -81,7 +77,7 @@ func Clean() {
8177 10 * time .Second ,
8278 )
8379 if err != nil {
84- closeTunnel (tunnel )
80+ closeTunnel (tunnel , key )
8581 continue
8682 }
8783
@@ -94,7 +90,7 @@ func Clean() {
9490 default :
9591 _ ,
_ ,
err := tunnel .
SshClient .
SendRequest (
"[email protected] " ,
true ,
nil )
9692 if err != nil {
97- closeTunnel (tunnel )
93+ closeTunnel (tunnel , key )
9894 logger .Sugar ().Warnw ("error when sending request" )
9995 }
10096
@@ -106,7 +102,7 @@ func Clean() {
106102 case <- ch :
107103 continue
108104 case <- time .After (10 * time .Second ):
109- closeTunnel (tunnel )
105+ closeTunnel (tunnel , key )
110106 continue
111107 }
112108 }
@@ -118,15 +114,13 @@ func Clean() {
118114func closeSession (s * Session , key string ) {
119115 s .Mutex .Lock ()
120116 s .CloseAllConnections ()
121- s .Mutex .Unlock ()
122-
123117 Sessions .Delete (key )
118+ s .Mutex .Unlock ()
124119}
125120
126- func closeTunnel (t * Tunnel ) {
121+ func closeTunnel (t * Tunnel , key string ) {
127122 t .Mutex .Lock ()
128123 t .Stop ()
124+ Tunnels .Delete (key )
129125 t .Mutex .Unlock ()
130-
131- t .errHandler ()
132126}
0 commit comments