Skip to content

Commit

Permalink
VM mod: request retry in process logs added (#219)
Browse files Browse the repository at this point in the history
(cherry picked from commit eda0829)
  • Loading branch information
Mikhail Kornilov committed Oct 14, 2020
1 parent 3cd4f7a commit af9d2ed
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion x/vm/internal/keeper/keeper_ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func (k Keeper) CloseConnections() {
// retryExecReq sends request with retry mechanism and waits for connection and execution.
// Contract: either RawModule or RawScript must be specified for RetryExecReq.
func (k Keeper) retryExecReq(ctx sdk.Context, req RetryExecReq) (retResp *vm_grpc.VMExecuteResponse, retErr error) {
const failedRetryLogPeriod = 100

doneCh := make(chan bool)
curAttempt := uint(0)
reqTimeout := time.Duration(req.ReqTimeoutInMs) * time.Millisecond
Expand Down Expand Up @@ -98,14 +100,19 @@ func (k Keeper) retryExecReq(ctx sdk.Context, req RetryExecReq) (retResp *vm_grp
return
}

if curAttempt == req.MaxAttempts {
if req.MaxAttempts != 0 && curAttempt == req.MaxAttempts {
retResp, retErr = nil, err
return
}

if curReqDur < reqTimeout {
time.Sleep(reqTimeout - curReqDur)
}

if curAttempt % failedRetryLogPeriod == 0 {
msg := fmt.Sprintf("Failing VM request: attempt %d / %d with %v timeout: %v", curAttempt, req.MaxAttempts, reqTimeout, time.Since(reqStartedAt))
k.GetLogger(ctx).Info(msg)
}
}
}()
<-doneCh
Expand Down

0 comments on commit af9d2ed

Please sign in to comment.