From d60d43c8c5f8068db44175d8503c08efeb8ef7da Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Tue, 23 Jan 2018 21:26:41 +0100 Subject: [PATCH 1/3] Wait before closing connection Connects to #30 Change-Type: patch Changelog-Entry: Wait until all channels/requests have been serviced before closing connection --- sshproxy.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sshproxy.go b/sshproxy.go index 0bb2a88..acd433e 100644 --- a/sshproxy.go +++ b/sshproxy.go @@ -30,6 +30,7 @@ import ( "os" "os/exec" "path/filepath" + "sync" "syscall" "time" @@ -154,6 +155,7 @@ func (s *Server) upgradeConnection(conn net.Conn) { // After successful handshake, handle new channels. Only the "session" type is supported. func (s *Server) handleChannels(chans <-chan ssh.NewChannel, conn *ssh.ServerConn) { + var wg sync.WaitGroup for newChannel := range chans { log.Printf("New SSH channel from %s", conn.RemoteAddr()) if chanType := newChannel.ChannelType(); chanType != "session" { @@ -170,12 +172,15 @@ func (s *Server) handleChannels(chans <-chan ssh.NewChannel, conn *ssh.ServerCon } // Do not block handling requests so we can service new channels + wg.Add(1) go func() { + defer wg.Done() if err := s.handleRequests(reqs, channel, conn); err != nil { s.handleError(err, nil) } }() } + wg.Wait() } // Service requests on given channel From 7e5ddb97c7d63f59005c90ebbca86663f16b58ab Mon Sep 17 00:00:00 2001 From: Will Boyce Date: Thu, 25 Jan 2018 11:00:10 +0000 Subject: [PATCH 2/3] Remove excessively verbose logging Change-Type: patch --- .errcheck.exclude | 2 ++ Makefile | 2 +- sshproxy.go | 25 +++++++------------------ 3 files changed, 10 insertions(+), 19 deletions(-) create mode 100644 .errcheck.exclude diff --git a/.errcheck.exclude b/.errcheck.exclude new file mode 100644 index 0000000..d7cfacd --- /dev/null +++ b/.errcheck.exclude @@ -0,0 +1,2 @@ +io.Copy +(net.Conn).Close diff --git a/Makefile b/Makefile index be8be44..d7f032b 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ lint: lint-dep gofmt -e -l -s . golint -set_exit_status ./... go tool vet . - errcheck -verbose ./... + errcheck -exclude .errcheck.exclude -verbose ./... test-dep: dep go test -i -v ./... diff --git a/sshproxy.go b/sshproxy.go index acd433e..89735b5 100644 --- a/sshproxy.go +++ b/sshproxy.go @@ -144,9 +144,7 @@ func (s *Server) upgradeConnection(conn net.Conn) { log.Printf("New SSH connection from %s (%s)", conn.RemoteAddr(), sshConn.ClientVersion()) defer func() { - if err := conn.Close(); err != nil { - s.handleError(err, nil) - } + conn.Close() log.Printf("Closed connection to %s", conn.RemoteAddr()) }() go ssh.DiscardRequests(reqs) @@ -261,10 +259,7 @@ func (s *Server) handleRequests(reqs <-chan *ssh.Request, channel ssh.Channel, c } break Loop } - case err := <-done: - if err != nil { - s.handleError(err, nil) - } + case <-done: break Loop } } @@ -308,12 +303,6 @@ func (s *Server) handleRequests(reqs <-chan *ssh.Request, channel ssh.Channel, c } func (s *Server) launchCommand(channel ssh.Channel, cmd *exec.Cmd, terminal *pty.Terminal) error { - ioCopy := func(dst io.Writer, src io.Reader) { - if _, err := io.Copy(dst, src); err != nil { - s.handleError(err, nil) - } - } - if s.shellCreds != nil { cmd.SysProcAttr = &syscall.SysProcAttr{Credential: s.shellCreds} } @@ -324,8 +313,8 @@ func (s *Server) launchCommand(channel ssh.Channel, cmd *exec.Cmd, terminal *pty return err } - go ioCopy(terminal, channel) - go ioCopy(channel, terminal) + go io.Copy(terminal, channel) + go io.Copy(channel, terminal) } else { stdout, err := cmd.StdoutPipe() if err != nil { @@ -346,9 +335,9 @@ func (s *Server) launchCommand(channel ssh.Channel, cmd *exec.Cmd, terminal *pty return err } - go ioCopy(stdin, channel) - go ioCopy(channel, stdout) - go ioCopy(channel.Stderr(), stderr) + go io.Copy(stdin, channel) + go io.Copy(channel, stdout) + go io.Copy(channel.Stderr(), stderr) } return nil From f9e154d798806955ff35bbb7d5b08cd81a62d3d6 Mon Sep 17 00:00:00 2001 From: "resin-io-versionbot[bot]" Date: Fri, 2 Feb 2018 19:04:10 +0000 Subject: [PATCH 3/3] v1.4.3 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db3e03b..cb5a944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY! This project adheres to [Semantic Versioning](http://semver.org/). +## v1.4.3 - 2018-02-02 + +* Remove excessively verbose logging #32 [Will Boyce] +* Wait until all channels/requests have been serviced before closing connection #32 [Alexis Svinartchouk] + ## v1.4.2 - 2017-11-30 * Use keyType during key generation to create correct key type #28 [Andreas Fitzek]