@@ -11,7 +11,9 @@ import (
1111 "path/filepath"
1212 "regexp"
1313 "strings"
14+ "time"
1415
16+ "github.com/avast/retry-go/v4"
1517 "github.com/google/go-github/v72/github"
1618 "github.com/pkg/errors"
1719 "github.com/smartcontractkit/chainlink-testing-framework/framework"
@@ -510,20 +512,33 @@ func registerSingleProto(
510512 }
511513
512514 url := fmt .Sprintf ("%s/subjects/%s/versions" , registryURL , subject )
515+ maxAttempts := uint (10 )
513516
514- resp , respErr := http .Post (url , "application/vnd.schemaregistry.v1+json" , bytes .NewReader (payload ))
515- if respErr != nil {
516- return 0 , errors .Wrap (respErr , "failed to post to schema registry" )
517- }
518- defer resp .Body .Close ()
517+ var resp * http.Response
518+ retry .Do (func () error {
519+ var respErr error
520+ resp , respErr = http .Post (url , "application/vnd.schemaregistry.v1+json" , bytes .NewReader (payload ))
521+ if respErr != nil {
522+ return errors .Wrap (respErr , "failed to post to schema registry" )
523+ }
519524
520- if resp .StatusCode >= 300 {
521- data , dataErr := io .ReadAll (resp .Body )
522- if dataErr != nil {
523- return 0 , errors .Wrap (dataErr , "failed to read response body" )
525+ if resp .StatusCode >= 300 {
526+ data , dataErr := io .ReadAll (resp .Body )
527+ if dataErr != nil {
528+ return errors .Wrap (dataErr , "failed to read response body" )
529+ }
530+ return fmt .Errorf ("schema registry error (%d): %s" , resp .StatusCode , data )
524531 }
525- return 0 , fmt .Errorf ("schema registry error (%d): %s" , resp .StatusCode , data )
526- }
532+
533+ return nil
534+ }, retry .Attempts (maxAttempts ), retry .Delay (100 * time .Millisecond ), retry .DelayType (retry .BackOffDelay ), retry .OnRetry (func (n uint , err error ) {
535+ framework .L .Debug ().Str ("attempt/max" , fmt .Sprintf ("%d/%d" , n , maxAttempts )).Msgf ("Retrying to register schema %s: %v" , subject , err )
536+ }), retry .RetryIf (func (err error ) bool {
537+ // we don't want to retry all errors, because some of them are are expected (e.g. missing dependencies)
538+ // and will be handled by higher-level code
539+ return strings .Contains (err .Error (), "connection reset by peer" )
540+ }))
541+ defer resp .Body .Close ()
527542
528543 var result struct {
529544 ID int `json:"id"`
0 commit comments