@@ -717,21 +717,24 @@ The next upload iteration will be delayed.`);
717
717
718
718
private async applyCheckpoint ( checkpoint : Checkpoint , abort : AbortSignal ) {
719
719
let result = await this . options . adapter . syncLocalDatabase ( checkpoint ) ;
720
+ const pending = this . pendingCrudUpload ;
721
+
720
722
if ( ! result . checkpointValid ) {
721
723
this . logger . debug ( 'Checksum mismatch in checkpoint, will reconnect' ) ;
722
724
// This means checksums failed. Start again with a new checkpoint.
723
725
// TODO: better back-off
724
726
await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
725
727
return { applied : false , endIteration : true } ;
726
- } else if ( ! result . ready ) {
728
+ } else if ( ! result . ready && pending != null ) {
727
729
// We have pending entries in the local upload queue or are waiting to confirm a write
728
- // checkpoint. See if that is happening right now.
729
- const pending = this . pendingCrudUpload ;
730
- if ( pending != null ) {
731
- await Promise . race ( [ pending , onAbortPromise ( abort ) ] ) ;
732
- }
733
-
734
- if ( abort . aborted || pending == null ) {
730
+ // checkpoint, which prevented this checkpoint from applying. Wait for that to complete and
731
+ // try again.
732
+ this . logger . debug (
733
+ 'Could not apply checkpoint due to local data. Waiting for in-progress upload before retrying.'
734
+ ) ;
735
+ await Promise . race ( [ pending , onAbortPromise ( abort ) ] ) ;
736
+
737
+ if ( abort . aborted ) {
735
738
return { applied : false , endIteration : true } ;
736
739
}
737
740
@@ -752,7 +755,7 @@ The next upload iteration will be delayed.`);
752
755
753
756
return { applied : true , endIteration : false } ;
754
757
} else {
755
- this . logger . debug ( 'Could not apply checkpoint even after waiting for uploads . Waiting for next sync complete line.' ) ;
758
+ this . logger . debug ( 'Could not apply checkpoint. Waiting for next sync complete line.' ) ;
756
759
return { applied : false , endIteration : false } ;
757
760
}
758
761
}
0 commit comments