Skip to content

Commit

Permalink
[fix] -timeout can control gossh print timeout
Browse files Browse the repository at this point in the history
gossh 打印结果的goroutine默认超时是45s,对于大任务会失败,修改为通过-timeout可以控制
  • Loading branch information
andesli committed Aug 4, 2020
1 parent d5ec942 commit f8332b4
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 5 deletions.
Binary file modified bin/386/linux/gossh
Binary file not shown.
Binary file modified bin/386/windows/gossh.exe
Binary file not shown.
Binary file modified bin/amd64/linux/gossh
Binary file not shown.
Binary file modified bin/amd64/windows/gossh.exe
Binary file not shown.
Binary file modified bin/arm64/linux/gossh
Binary file not shown.
10 changes: 7 additions & 3 deletions output/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
)

const (
timeout = 45
TIMEOUT = 4500
)

//new print result
Expand All @@ -46,13 +46,17 @@ func Print(res machine.Result) {
fmt.Println("----------------------------------------------------------")
}

func PrintResults2(crs chan machine.Result, ls int, wt *sync.WaitGroup, ccons chan struct{}) {
func PrintResults2(crs chan machine.Result, ls int, wt *sync.WaitGroup, ccons chan struct{}, timeout int) {
if timeout == 0 {
timeout = TIMEOUT
}

for i := 0; i < ls; i++ {
select {
case rs := <-crs:
//PrintResult(rs.Ip, rs.Cmd, rs.Result)
Print(rs)
case <-time.After(time.Second * timeout):
case <-time.After(time.Second * time.Duration(timeout)):
fmt.Printf("getSSHClient error,SSH-Read-TimeOut,Timeout=%ds", timeout)
}
wt.Done()
Expand Down
4 changes: 2 additions & 2 deletions run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func ServersRun(cmd string, cu *CommonUser, wt *sync.WaitGroup, crs chan machine
}
} else {
log.Debug("并行执行")
go output.PrintResults2(crs, ls, wt, ccons)
go output.PrintResults2(crs, ls, wt, ccons, timeout)

for _, h := range hosts {
ccons <- struct{}{}
Expand Down Expand Up @@ -132,7 +132,7 @@ func ServersPush(src, dst string, cu *CommonUser, ipFile string, wt *sync.WaitGr
fmt.Printf("[servers]=%v\n", ips)

ls := len(hosts)
go output.PrintResults2(crs, ls, wt, ccons)
go output.PrintResults2(crs, ls, wt, ccons, timeout)

for _, h := range hosts {
ccons <- struct{}{}
Expand Down

0 comments on commit f8332b4

Please sign in to comment.