@@ -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,23 +512,33 @@ func registerSingleProto(
510512 }
511513
512514 url := fmt .Sprintf ("%s/subjects/%s/versions" , registryURL , subject )
513- // Force IPv4 to avoid Docker IPv6 port forwarding issues
514- url = strings .Replace (url , "localhost" , "127.0.0.1" , 1 )
515- framework .L .Debug ().Msgf ("Registering schema to URL: %s" , url )
515+ maxAttempts := uint (10 )
516516
517- resp , respErr := http .Post (url , "application/vnd.schemaregistry.v1+json" , bytes .NewReader (payload ))
518- if respErr != nil {
519- return 0 , errors .Wrap (respErr , "failed to post to schema registry" )
520- }
521- 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+ }
522524
523- if resp .StatusCode >= 300 {
524- data , dataErr := io .ReadAll (resp .Body )
525- if dataErr != nil {
526- 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 )
527531 }
528- return 0 , fmt .Errorf ("schema registry error (%d): %s" , resp .StatusCode , data )
529- }
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 ()
530542
531543 var result struct {
532544 ID int `json:"id"`
0 commit comments