From b5fc545ce20234cd2fe476bfd22ab6022a55aeab Mon Sep 17 00:00:00 2001 From: Joshua Elliott Date: Thu, 16 Aug 2018 18:28:20 +1000 Subject: [PATCH] [easyssh] Scan stdout and stderr in Stream in seperate goroutines. (appleboy/easyssh-proxy#41) Fixes appleboy/easyssh-proxy#40. Splits stdout and stderr scanning into seperate goroutines, and waits on both to finish through use of a wait group. Also changed `res` chan to use empty structs as they take up less memory. https://github.com/appleboy/drone-ssh/commit/e788e0d12bd --- .../github.com/appleboy/easyssh-proxy/easyssh.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/vendor/github.com/appleboy/easyssh-proxy/easyssh.go b/vendor/github.com/appleboy/easyssh-proxy/easyssh.go index b6e60ec..80be120 100644 --- a/vendor/github.com/appleboy/easyssh-proxy/easyssh.go +++ b/vendor/github.com/appleboy/easyssh-proxy/easyssh.go @@ -13,6 +13,7 @@ import ( "net" "os" "path/filepath" + "sync" "time" "golang.org/x/crypto/ssh" @@ -201,17 +202,28 @@ func (ssh_conf *MakeConfig) Stream(command string, timeout time.Duration) (<-cha defer session.Close() timeoutChan := time.After(timeout * time.Second) - res := make(chan bool, 1) + res := make(chan struct{}, 1) + var resWg sync.WaitGroup + resWg.Add(2) go func() { for stdoutScanner.Scan() { stdoutChan <- stdoutScanner.Text() } + resWg.Done() + }() + + go func() { for stderrScanner.Scan() { stderrChan <- stderrScanner.Text() } + resWg.Done() + }() + + go func() { + resWg.Wait() // close all of our open resources - res <- true + res <- struct{}{} }() select {