mirror of
https://github.com/appleboy/drone-ssh.git
synced 2025-07-02 21:52:51 +08:00
fix block channel.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
5b0ba436e2
commit
daaf2e2b25
49
plugin.go
49
plugin.go
@ -11,8 +11,6 @@ import (
|
||||
"github.com/appleboy/easyssh-proxy"
|
||||
)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
const (
|
||||
missingHostOrUser = "Error: missing server host or user"
|
||||
missingPasswordOrKey = "Error: can't connect without a private SSH key or password"
|
||||
@ -59,6 +57,7 @@ func (p Plugin) Exec() error {
|
||||
return fmt.Errorf(setPasswordandKey)
|
||||
}
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(len(p.Config.Host))
|
||||
errChannel := make(chan error, 1)
|
||||
finished := make(chan bool, 1)
|
||||
@ -88,31 +87,33 @@ func (p Plugin) Exec() error {
|
||||
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
|
||||
if err != nil {
|
||||
errChannel <- err
|
||||
}
|
||||
// read from the output channel until the done signal is passed
|
||||
stillGoing := true
|
||||
isTimeout := true
|
||||
for stillGoing {
|
||||
select {
|
||||
case isTimeout = <-doneChan:
|
||||
stillGoing = false
|
||||
case outline := <-stdoutChan:
|
||||
p.log(host, "outputs:", outline)
|
||||
case errline := <-stderrChan:
|
||||
p.log(host, "errors:", errline)
|
||||
case err = <-errChan:
|
||||
} else {
|
||||
// read from the output channel until the done signal is passed
|
||||
stillGoing := true
|
||||
isTimeout := true
|
||||
for stillGoing {
|
||||
select {
|
||||
case isTimeout = <-doneChan:
|
||||
stillGoing = false
|
||||
case outline := <-stdoutChan:
|
||||
p.log(host, "outputs:", outline)
|
||||
case errline := <-stderrChan:
|
||||
p.log(host, "errors:", errline)
|
||||
case err = <-errChan:
|
||||
}
|
||||
}
|
||||
|
||||
// get exit code or command error.
|
||||
if err != nil {
|
||||
errChannel <- err
|
||||
}
|
||||
|
||||
// command time out
|
||||
if !isTimeout {
|
||||
errChannel <- fmt.Errorf(commandTimeOut)
|
||||
}
|
||||
}
|
||||
|
||||
// get exit code or command error.
|
||||
if err != nil {
|
||||
errChannel <- err
|
||||
}
|
||||
|
||||
// command time out
|
||||
if !isTimeout {
|
||||
errChannel <- fmt.Errorf(commandTimeOut)
|
||||
}
|
||||
wg.Done()
|
||||
}(host)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user