appleboy / drone-ssh

Drone plugin for executing remote ssh commands
MIT License
251 stars 74 forks source link

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

Closed christianruhstaller closed 1 year ago

christianruhstaller commented 2 years ago

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":

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.

thematrixdev commented 1 year ago

I am using image: appleboy/drone-ssh. How to pin the version to v0.1.4? image: appleboy/drone-ssh:v0.1.4 does not work.

phiexz commented 1 year ago

I am using image: appleboy/drone-ssh. How to pin the version to v0.1.4? image: appleboy/drone-ssh:v0.1.4 does not work.

0.1.4 is for ssh-action if you're using drone-ssh, pin version to 1.6.3

appleboy commented 1 year ago

fixed in https://github.com/appleboy/drone-ssh/releases/tag/v1.6.5