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 3, 2020
1 parent 1e24dc8 commit a3b17a7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 30 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
23 changes: 1 addition & 22 deletions go/worker/common/committee/runtime_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
"errors"
"sync"
"time"

"github.com/cenkalti/backoff/v4"
"github.com/opentracing/opentracing-go"

"github.com/oasisprotocol/oasis-core/go/common/cbor"
Expand All @@ -20,11 +18,6 @@ import (
storage "github.com/oasisprotocol/oasis-core/go/storage/api"
)

const (
retryInterval = 1 * time.Second
maxRetries = 15
)

var (
errMethodNotSupported = errors.New("method not supported")
errEndpointNotSupported = errors.New("RPC endpoint not supported")
Expand Down Expand Up @@ -164,21 +157,7 @@ func (n *computeRuntimeHostNotifier) watchPolicyUpdates() {
SignedPolicyRaw: raw,
}}

var response *protocol.Body
call := func() error {
resp, err := n.host.Call(n.ctx, req)
if err != nil {
n.logger.Error("failed to dispatch RPC call to runtime",
"err", err,
)
return err
}
response = resp
return nil
}

retry := backoff.WithMaxRetries(backoff.NewConstantBackOff(retryInterval), maxRetries)
err := backoff.Retry(call, backoff.WithContext(retry, n.ctx))
response, err := n.host.Call(n.ctx, req)
if err != nil {
n.logger.Error("failed dispatching key manager policy update to runtime",
"err", err,
Expand Down

0 comments on commit a3b17a7

Please sign in to comment.