Skip to content

Commit fc9b5a8

Browse files
authored
Add StartTimeout handling to Docker Runner (#3135)
* Add StartTimeout handling to Docker Runner * linting issue
1 parent 63026ce commit fc9b5a8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

pkg/docker/runner.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,31 @@ func (n *Runner) Run(ctx context.Context, f fn.Function, address string, startTi
124124
return job, errors.Wrap(err, "runner unable to start container")
125125
}
126126

127+
readyCh := make(chan error, 1)
128+
go func() {
129+
deadline := time.Now().Add(startTimeout)
130+
for {
131+
if time.Now().After(deadline) {
132+
readyCh <- fmt.Errorf("container did not become ready in %v", startTimeout)
133+
return
134+
}
135+
if err = dial(host, port, 500*time.Millisecond); err == nil {
136+
readyCh <- nil
137+
return
138+
}
139+
time.Sleep(100 * time.Millisecond)
140+
}
141+
}()
142+
143+
select {
144+
case err = <-readyCh:
145+
if err != nil {
146+
return job, err
147+
}
148+
case <-ctx.Done():
149+
return job, ctx.Err()
150+
}
151+
127152
// Stopper
128153
stop := func() error {
129154
var (

0 commit comments

Comments
 (0)