From ad5436e3f62cc3bf83643a2d7548fb7da02177a9 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Mon, 30 Dec 2019 00:10:03 +0100 Subject: [PATCH] ssh commands: improve command ended detection Sometime we can have this error: read |0: file already closed reading from the command standard error, this means that the command is already finished so we don't need to do nothing. This happen randomically while running the test cases on travis. --- .travis.yml | 1 - README.md | 2 +- sftpd/ssh_cmd.go | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7de5a331..e85bd938 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ os: - osx go: - - "1.12.x" - "1.13.x" env: diff --git a/README.md b/README.md index b252e197..5578d919 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Regularly the test cases are manually executed and pass on Windows. Other UNIX v ## Requirements -- Go 1.12 or higher as build only dependency. +- Go 1.13 or higher as build only dependency. - A suitable SQL server or key/value store to use as data provider: PostreSQL 9.4+ or MySQL 5.6+ or SQLite 3.x or bbolt 1.3.x ## Installation diff --git a/sftpd/ssh_cmd.go b/sftpd/ssh_cmd.go index c5bf73a5..eddba2c0 100644 --- a/sftpd/ssh_cmd.go +++ b/sftpd/ssh_cmd.go @@ -261,7 +261,8 @@ func (c *sshCommand) executeSystemCommand(command systemCommand) error { w, e := transfer.copyFromReaderToWriter(c.connection.channel.Stderr(), stderr, 0) c.connection.Log(logger.LevelDebug, logSenderSSH, "command: %#v, copy from sdterr to remote command ended, written: %v err: %v", c.connection.command, w, e) - if e != nil || w > 0 { + // os.ErrClosed means that the command is finished so we don't need to to nothing + if (e != nil && !errors.Is(e, os.ErrClosed)) || w > 0 { once.Do(closeCmdOnError) } }()