@@ -471,6 +471,7 @@ func (commitReq *CommitRequestV2) processCommit() {
471
471
return
472
472
}
473
473
if commitReq .commitMask .CountOnes () < commitReq .consensusThresh {
474
+ commitReq .commitMask = zboxutil .NewUint128 (0 )
474
475
commitReq .result = ErrorCommitResult ("Failed to get reference path" )
475
476
return
476
477
}
@@ -624,41 +625,78 @@ func getReferencePathV2(blobber *blockchain.StorageNode, allocationID, allocatio
624
625
return trie , nil
625
626
}
626
627
now := time .Now ()
627
- req , err := zboxutil .NewReferencePathRequestV2 (blobber .Baseurl , allocationID , allocationTx , sig , paths , false )
628
- if err != nil {
629
- l .Logger .Error ("Creating ref path req" , err )
630
- return nil , err
631
- }
632
- var lR ReferencePathResultV2
633
- ctx , cncl := context .WithTimeout (context .Background (), (time .Second * 30 ))
634
- err = zboxutil .HttpDo (ctx , cncl , req , func (resp * http.Response , err error ) error {
635
- if err != nil {
636
- l .Logger .Error ("Ref path error:" , err )
637
- return err
638
- }
639
- defer resp .Body .Close ()
640
- respBody , err := io .ReadAll (resp .Body )
641
- if err != nil {
642
- l .Logger .Error ("Ref path: Resp" , err )
643
- return err
644
- }
645
- if resp .StatusCode != http .StatusOK {
646
- return errors .New (
647
- strconv .Itoa (resp .StatusCode ),
648
- fmt .Sprintf ("Reference path error response: Status: %d - %s " ,
649
- resp .StatusCode , string (respBody )))
650
- }
651
- err = json .Unmarshal (respBody , & lR )
652
- if err != nil {
653
- l .Logger .Error ("Reference path json decode error: " , err )
654
- return err
655
- }
656
- return nil
657
- })
628
+ var (
629
+ shouldContinue bool
630
+ err error
631
+ lR ReferencePathResultV2
632
+ )
633
+ for retries := 0 ; retries < 3 ; retries ++ {
634
+ err , shouldContinue = func () (err error , shouldContinue bool ) {
635
+ var req * http.Request
636
+ req , err = zboxutil .NewReferencePathRequestV2 (blobber .Baseurl , allocationID , allocationTx , sig , paths , false )
637
+ if err != nil {
638
+ l .Logger .Error ("Creating ref path req" , err )
639
+ return
640
+ }
658
641
642
+ ctx , cncl := context .WithTimeout (context .Background (), (time .Second * 30 ))
643
+ err = zboxutil .HttpDo (ctx , cncl , req , func (resp * http.Response , err error ) error {
644
+ if err != nil {
645
+ l .Logger .Error ("Ref path error:" , err )
646
+ if errors .Is (err , http .ErrServerClosed ) || strings .Contains (err .Error (), "GOAWAY" ) {
647
+ shouldContinue = true
648
+ }
649
+ return err
650
+ }
651
+ defer resp .Body .Close ()
652
+ respBody , err := io .ReadAll (resp .Body )
653
+ if err != nil {
654
+ l .Logger .Error ("Ref path: Resp" , err )
655
+ if strings .Contains (err .Error (), "GOAWAY" ) || errors .Is (err , io .ErrUnexpectedEOF ) {
656
+ shouldContinue = true
657
+ }
658
+ return err
659
+ }
660
+ if resp .StatusCode != http .StatusOK {
661
+ if resp .StatusCode == http .StatusTooManyRequests {
662
+ logger .Logger .Debug (blobber .Baseurl ,
663
+ " got too many request error. Retrying" )
664
+
665
+ var r int
666
+ r , err = zboxutil .GetRateLimitValue (resp )
667
+ if err != nil {
668
+ logger .Logger .Error (err )
669
+ return err
670
+ }
671
+
672
+ time .Sleep (time .Duration (r ) * time .Second )
673
+ shouldContinue = true
674
+ return err
675
+ }
676
+ return errors .New (
677
+ strconv .Itoa (resp .StatusCode ),
678
+ fmt .Sprintf ("Reference path error response: Status: %d - %s " ,
679
+ resp .StatusCode , string (respBody )))
680
+ }
681
+ err = json .Unmarshal (respBody , & lR )
682
+ if err != nil {
683
+ l .Logger .Error ("Reference path json decode error: " , err )
684
+ return err
685
+ }
686
+ return nil
687
+ })
688
+ return
689
+ }()
690
+ if shouldContinue {
691
+ continue
692
+ } else {
693
+ break
694
+ }
695
+ }
659
696
if err != nil {
660
697
return nil , err
661
698
}
699
+
662
700
elapsedRefPath := time .Since (now )
663
701
mu .Lock ()
664
702
defer mu .Unlock ()
@@ -725,6 +763,9 @@ func submitWriteMarker(wmData, metaData []byte, blobber *blockchain.StorageNode,
725
763
respBody , err = io .ReadAll (resp .Body )
726
764
if err != nil {
727
765
logger .Logger .Error ("Response read: " , err )
766
+ if errors .Is (err , io .ErrUnexpectedEOF ) {
767
+ shouldContinue = true
768
+ }
728
769
return
729
770
}
730
771
if resp .StatusCode == http .StatusOK {
@@ -764,6 +805,13 @@ func submitWriteMarker(wmData, metaData []byte, blobber *blockchain.StorageNode,
764
805
return
765
806
}
766
807
808
+ trimmed := strings .TrimSpace (string (respBody ))
809
+ if strings .HasPrefix (trimmed , "<html>" ) {
810
+ time .Sleep (5 * time .Second )
811
+ shouldContinue = true
812
+ return
813
+ }
814
+
767
815
err = thrown .New ("commit_error" ,
768
816
fmt .Sprintf ("Got error response %s with status %d" , respBody , resp .StatusCode ))
769
817
return
0 commit comments