Skip to content
Permalink
Browse files

Fixed channel cleanup

  • Loading branch information
antoniomika committed Dec 24, 2019
1 parent 7d1db50 commit 28b9614a16f793b56df9507cd3b8387df6951a4d
Showing with 8 additions and 25 deletions.
  1. +0 −19 main.go
  2. +8 −6 requests.go
19 main.go
@@ -332,25 +332,6 @@ func main() {
func (s *SSHConnection) CleanUp(state *State) {
close(s.Close)
s.SSHConn.Close()
s.Listeners.Range(func(key, val interface{}) bool {
_, ok := key.(*net.UnixAddr)

if ok {
actualUnixListener, ok := val.(*net.UnixListener)

if ok {
actualUnixListener.Close()
} else {
actualUnixConn := val.(*net.UnixConn)
actualUnixConn.Close()
}
} else {
actualTCPListener := val.(*net.TCPListener)
actualTCPListener.Close()
}

return true
})
state.SSHConnections.Delete(s.SSHConn.RemoteAddr())
log.Println("Closed SSH connection for:", s.SSHConn.RemoteAddr(), "user:", s.SSHConn.User())
}
@@ -93,11 +93,18 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state
state.Listeners.Store(chanListener.Addr(), chanListener)
sshConn.Listeners.Store(chanListener.Addr(), chanListener)

defer func() {
cleanupChanListener := func() {
chanListener.Close()
state.Listeners.Delete(chanListener.Addr())
sshConn.Listeners.Delete(chanListener.Addr())
os.Remove(tmpfile.Name())
}

defer cleanupChanListener()

go func() {
<-sshConn.Close
cleanupChanListener()
}()

connType := "tcp"
@@ -177,11 +184,6 @@ func handleRemoteForward(newRequest *ssh.Request, sshConn *SSHConnection, state

sendMessage(sshConn, requestMessages, false)

go func() {
<-sshConn.Close
chanListener.Close()
}()

for {
cl, err := chanListener.Accept()
if err != nil {

0 comments on commit 28b9614

Please sign in to comment.
You can’t perform that action at this time.