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.
This commit is contained in:
Nicola Murino
2019-12-30 00:10:03 +01:00
parent 20606a0043
commit ad5436e3f6
3 changed files with 3 additions and 3 deletions

View File

@@ -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)
}
}()