Skip to content

Commit e59becd

Browse files
committed
Timeout waiting for the io.Copy call.
1 parent 4b4195f commit e59becd

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

buildbox/script.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,25 @@ func RunScript(dir string, script string, env []string, callback func(Process))
139139

140140
Logger.Debugf("Process with PID: %d finished with Exit Status: %s", process.Pid, process.ExitStatus)
141141

142+
// Make a chanel that we'll use as a timeout
143+
c := make(chan int, 1)
144+
145+
// Start waiting for the routines to finish
142146
Logger.Debug("Waiting for io.Copy and incremental output to finish")
143-
w.Wait()
147+
go func() {
148+
w.Wait()
149+
c <- 1
150+
}()
151+
152+
// Sometimes (in docker containers) io.Copy never seems to finish. This is a mega
153+
// hack around it. If it doesn't finish after 1 second, just continue.
154+
// TODO: Whyyyyy!?!?!?
155+
select {
156+
case _ = <-c:
157+
// nothing, wait finished fine.
158+
case <-time.After(1 * time.Second):
159+
Logger.Error("Timed out waiting for the routines to finish. Forcefully moving on.")
160+
}
144161

145162
// Copy the final output back to the process
146163
process.Output = buffer.String()

0 commit comments

Comments
 (0)