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 83e9a9b commit 228e76a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .changelog/2967.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/runtime/host/sandbox: Retry Call in case the runtime is not yet ready
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 228e76a

Please sign in to comment.