Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions pkg/docker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,35 @@ func (n *Runner) Run(ctx context.Context, f fn.Function, address string, startTi
}
}()

// TODO: use StartTimeout
// - Start a goroutine which queries for, or will be notified when, the
// container has successfully started. If the startTimeout is reached
// before then, send a timeout error to the runtimeErrCh

if err = c.ContainerStart(ctx, id, container.StartOptions{}); err != nil {
return job, errors.Wrap(err, "runner unable to start container")
}

readyCh := make(chan error, 1)
go func() {
deadline := time.Now().Add(startTimeout)
for {
if time.Now().After(deadline) {
readyCh <- fmt.Errorf("container did not become ready in %v", startTimeout)
return
}
if err = dial(host, port, 500*time.Millisecond); err == nil {
readyCh <- nil
return
}
time.Sleep(100 * time.Millisecond)
}
}()

select {
case err = <-readyCh:
if err != nil {
return job, err
}
case <-ctx.Done():
return job, ctx.Err()
}

// Stopper
stop := func() error {
var (
Expand Down
Loading