drone-ssh icon indicating copy to clipboard operation
drone-ssh copied to clipboard

Channels stdoutChan and stderrChan still receive messages after they are closed resulting in messy output

Open christianruhstaller opened this issue 3 years ago • 0 comments

Output:

======CMD======
exit 0
======END======
out: 
err: 
err: 
out: 
out: 
out: 
out: 
err: 
err: 
err: 
out: 
err: 
out: 
out: 
out: 
out: 
err: 
err: 
err: 
out: 
==============================================
✅ Successfully executed commands to all host.
==============================================

The problem is that the receiving part does not check if the received message has the status "ok":

  • https://github.com/appleboy/drone-ssh/blob/1dcc9acbe58edfbf2d1a80357dfcfc8bd5b49640/plugin.go#L129
  • https://github.com/appleboy/drone-ssh/blob/1dcc9acbe58edfbf2d1a80357dfcfc8bd5b49640/plugin.go#L131

With the following fix the problem can be bypassed on the client side:

case outline, ok := <-stdoutChan:
if ok {
	p.log(host, "out:", outline)
}

case errline, ok := <-stderrChan:
if ok {
	p.log(host, "err:", errline)
}

The problem started with following pull request from easyssh-proxy: https://github.com/appleboy/easyssh-proxy/pull/66

If you step through the code the channels get closed and still receive some messages after. I could not figure out from which part of the code the messages come, after the channel was closed. It seems that there is still a race condition which leads to this behavior?

In our specific case the empty err and out messages where so large that we ran into an timeout and the pipeline cancelled.

christianruhstaller avatar Jun 16 '22 15:06 christianruhstaller