Skip to content

Commit

Permalink
go/runtime/host/sandbox: Retry Call in case the runtime is not yet ready
Browse files Browse the repository at this point in the history
  • Loading branch information
kostko committed Jun 2, 2020
1 parent 9865f5a commit c3cec68
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions go/runtime/host/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,26 @@ func (r *sandboxedRuntime) ID() common.Namespace {
}

// Implements host.Runtime.
func (r *sandboxedRuntime) Call(ctx context.Context, body *protocol.Body) (*protocol.Body, error) {
r.RLock()
conn := r.conn
r.RUnlock()

if conn == nil {
return nil, fmt.Errorf("runtime is not ready")
func (r *sandboxedRuntime) Call(ctx context.Context, body *protocol.Body) (rsp *protocol.Body, err error) {
callFn := func() error {
r.RLock()
conn := r.conn
r.RUnlock()

if conn == nil {
return fmt.Errorf("runtime is not ready")
}
rsp, err = r.conn.Call(ctx, body)
if err != nil {
// All protocol-level errors are permanent.
return backoff.Permanent(err)
}
return nil
}
return r.conn.Call(ctx, body)

// Retry call in case the runtime is not yet ready.
err = backoff.Retry(callFn, backoff.WithContext(backoff.NewExponentialBackOff(), ctx))
return
}

// Implements host.Runtime.
Expand Down

0 comments on commit c3cec68

Please sign in to comment.