Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/runtime/host/sandbox: Retry Call in case the runtime is not yet ready #2967

Merged
merged 1 commit into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
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
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) {
kostko marked this conversation as resolved.
Show resolved Hide resolved
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)
kostko marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
n.logger.Error("failed dispatching key manager policy update to runtime",
"err", err,
Expand Down