Skip to content
Permalink
Browse files

Fixed connection close during notty session

  • Loading branch information
antoniomika committed Nov 29, 2019
1 parent 9226761 commit 5e19adc8c629c2dd82285bf227b285d6135c8fca
Showing with 28 additions and 1 deletion.
  1. +9 −1 channels.go
  2. +5 −0 handle.go
  3. +14 −0 main.go
@@ -42,6 +42,8 @@ func handleSession(newChannel ssh.NewChannel, sshConn *SSHConnection, state *Sta
data := make([]byte, 4096)
dataRead, err := connection.Read(data)
if err != nil && err == io.EOF {
break
} else if err != nil {
select {
case <-sshConn.Close:
break
@@ -123,7 +125,13 @@ func handleAlias(newChannel ssh.NewChannel, sshConn *SSHConnection, state *State
sshConn.Listeners.Store(conn.RemoteAddr(), nil)

copyBoth(conn, connection, false)
sshConn.CleanUp(state)

select {
case <-sshConn.Close:
break
default:
sshConn.CleanUp(state)
}
}

func writeToSession(connection ssh.Channel, c string) {
@@ -22,6 +22,11 @@ func handleRequest(newRequest *ssh.Request, sshConn *SSHConnection, state *State
case "tcpip-forward":
go checkSession(newRequest, sshConn, state)
handleRemoteForward(newRequest, sshConn, state)
case "keepalive@openssh.com":
err := newRequest.Reply(true, nil)
if err != nil {
log.Println("Error replying to socket request:", err)
}
default:
err := newRequest.Reply(false, nil)
if err != nil {
14 main.go
@@ -267,6 +267,20 @@ func main() {

state.SSHConnections.Store(sshConn.RemoteAddr(), holderConn)

go func() {
err := sshConn.Wait()
if err != nil && *debug {
log.Println("Closing SSH connection:", err)
}

select {
case <-holderConn.Close:
break
default:
holderConn.CleanUp(state)
}
}()

go handleRequests(reqs, holderConn, state)
go handleChannels(chans, holderConn, state)

0 comments on commit 5e19adc

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