-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Cleaner cannot delete objects from pool occuring memory leaks
- Loading branch information
1 parent
96ef656
commit 5e07cc5
Showing
2 changed files
with
11 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,13 +65,9 @@ func Clean() { | |
} | ||
} | ||
|
||
for _, tunnel := range Tunnels.Connections { | ||
if now.Sub(tunnel.LastConnection).Seconds() > 266 { | ||
closeTunnel(tunnel) | ||
continue | ||
} | ||
|
||
if tunnel.SshClient == nil { | ||
for key, tunnel := range Tunnels.Connections { | ||
if now.Sub(tunnel.LastConnection).Seconds() > 266 || tunnel.SshClient == nil { | ||
closeTunnel(tunnel, key) | ||
continue | ||
} | ||
|
||
|
@@ -81,7 +77,7 @@ func Clean() { | |
10*time.Second, | ||
) | ||
if err != nil { | ||
closeTunnel(tunnel) | ||
closeTunnel(tunnel, key) | ||
continue | ||
} | ||
|
||
|
@@ -94,7 +90,7 @@ func Clean() { | |
default: | ||
_, _, err := tunnel.SshClient.SendRequest("[email protected]", true, nil) | ||
if err != nil { | ||
closeTunnel(tunnel) | ||
closeTunnel(tunnel, key) | ||
logger.Sugar().Warnw("error when sending request") | ||
} | ||
|
||
|
@@ -106,7 +102,7 @@ func Clean() { | |
case <-ch: | ||
continue | ||
case <-time.After(10 * time.Second): | ||
closeTunnel(tunnel) | ||
closeTunnel(tunnel, key) | ||
continue | ||
} | ||
} | ||
|
@@ -118,15 +114,13 @@ func Clean() { | |
func closeSession(s *Session, key string) { | ||
s.Mutex.Lock() | ||
s.CloseAllConnections() | ||
s.Mutex.Unlock() | ||
|
||
Sessions.Delete(key) | ||
s.Mutex.Unlock() | ||
} | ||
|
||
func closeTunnel(t *Tunnel) { | ||
func closeTunnel(t *Tunnel, key string) { | ||
t.Mutex.Lock() | ||
t.Stop() | ||
Tunnels.Delete(key) | ||
t.Mutex.Unlock() | ||
|
||
t.errHandler() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters