-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9177 from filecoin-project/9171-add-retries-to-mp…
…ool-push-message feat: message: Add retries to mpool push message from lotus miner
- Loading branch information
Showing
18 changed files
with
91 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package retry | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"time" | ||
|
||
logging "github.com/ipfs/go-log/v2" | ||
) | ||
|
||
var log = logging.Logger("retry") | ||
|
||
func ErrorIsIn(err error, errorTypes []error) bool { | ||
for _, etype := range errorTypes { | ||
tmp := reflect.New(reflect.PointerTo(reflect.ValueOf(etype).Elem().Type())).Interface() | ||
if errors.As(err, tmp) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func Retry[T any](attempts int, initialBackoff time.Duration, errorTypes []error, f func() (T, error)) (result T, err error) { | ||
for i := 0; i < attempts; i++ { | ||
if i > 0 { | ||
log.Info("Retrying after error:", err) | ||
time.Sleep(initialBackoff) | ||
initialBackoff *= 2 | ||
} | ||
result, err = f() | ||
if err == nil || !ErrorIsIn(err, errorTypes) { | ||
return result, err | ||
} | ||
} | ||
log.Errorf("Failed after %d attempts, last error: %s", attempts, err) | ||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package retry | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/filecoin-project/go-jsonrpc" | ||
) | ||
|
||
func TestRetryErrorIsInTrue(t *testing.T) { | ||
errorsToRetry := []error{&jsonrpc.RPCConnectionError{}} | ||
require.True(t, ErrorIsIn(&jsonrpc.RPCConnectionError{}, errorsToRetry)) | ||
} | ||
|
||
func TestRetryErrorIsInFalse(t *testing.T) { | ||
errorsToRetry := []error{&jsonrpc.RPCConnectionError{}} | ||
require.False(t, ErrorIsIn(xerrors.Errorf("random error"), errorsToRetry)) | ||
} | ||
|
||
func TestRetryWrappedErrorIsInTrue(t *testing.T) { | ||
errorsToRetry := []error{&jsonrpc.RPCConnectionError{}} | ||
require.True(t, ErrorIsIn(xerrors.Errorf("wrapped: %w", &jsonrpc.RPCConnectionError{}), errorsToRetry)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ARG GO_VERSION=1.17.9 | ||
ARG GO_VERSION=1.18.1 | ||
|
||
FROM golang:${GO_VERSION}-buster | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ARG GO_VERSION=1.17.9 | ||
ARG GO_VERSION=1.18.1 | ||
|
||
FROM golang:${GO_VERSION}-buster as downloader | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ARG GO_VERSION=1.17.9 | ||
ARG GO_VERSION=1.18.1 | ||
|
||
FROM golang:${GO_VERSION}-buster as downloader | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters