@@ -644,7 +644,10 @@ cfg_sync! {
644
644
645
645
let mut bg_abort: Option <std:: sync:: Arc <crate :: sync:: DropAbort >> = None ;
646
646
647
+
647
648
if let Some ( sync_interval) = sync_interval {
649
+ let ( cancel_tx, mut cancel_rx) = tokio:: sync:: oneshot:: channel:: <( ) >( ) ;
650
+
648
651
let sync_span = tracing:: debug_span!( "sync_interval" ) ;
649
652
let _enter = sync_span. enter( ) ;
650
653
@@ -659,7 +662,8 @@ cfg_sync! {
659
662
// `bootstrap_db` (for synced dbs) before calling connect. Otherwise, the sync
660
663
// protocol skips calling `export` endpoint causing slowdown in initial bootstrap.
661
664
let conn = db. connect( ) ?;
662
- let jh = tokio:: spawn(
665
+
666
+ tokio:: spawn(
663
667
async move {
664
668
let mut interval = tokio:: time:: interval( sync_interval) ;
665
669
@@ -669,21 +673,32 @@ cfg_sync! {
669
673
interval. tick( ) . await ;
670
674
671
675
let mut ctx = sync_ctx. lock( ) . await ;
676
+
672
677
if remote_writes {
673
- if let Err ( e) = crate :: sync:: try_pull( & mut ctx, & conn) . await {
674
- tracing:: error!( "sync error: {}" , e) ;
678
+ tokio:: select! {
679
+ _ = & mut cancel_rx => break ,
680
+ result = crate :: sync:: try_pull( & mut ctx, & conn) => {
681
+ if let Err ( e) = result {
682
+ tracing:: error!( "sync error: {}" , e) ;
683
+ }
684
+ }
675
685
}
676
686
} else {
677
- if let Err ( e) = crate :: sync:: sync_offline( & mut ctx, & conn) . await {
678
- tracing:: error!( "sync error: {}" , e) ;
687
+ tokio:: select! {
688
+ _ = & mut cancel_rx => break ,
689
+ result = crate :: sync:: sync_offline( & mut ctx, & conn) => {
690
+ if let Err ( e) = result {
691
+ tracing:: error!( "sync error: {}" , e) ;
692
+ }
693
+ }
679
694
}
680
695
}
681
696
}
682
697
}
683
698
. instrument( tracing:: debug_span!( "sync interval thread" ) ) ,
684
699
) ;
685
700
686
- bg_abort. replace( std:: sync:: Arc :: new( crate :: sync:: DropAbort ( jh . abort_handle ( ) ) ) ) ;
701
+ bg_abort. replace( std:: sync:: Arc :: new( crate :: sync:: DropAbort ( Some ( cancel_tx ) ) ) ) ;
687
702
}
688
703
689
704
Ok ( Database {
0 commit comments