@@ -644,7 +644,10 @@ cfg_sync! {
644644
645645 let mut bg_abort: Option <std:: sync:: Arc <crate :: sync:: DropAbort >> = None ;
646646
647+
647648 if let Some ( sync_interval) = sync_interval {
649+ let ( cancel_tx, mut cancel_rx) = tokio:: sync:: oneshot:: channel:: <( ) >( ) ;
650+
648651 let sync_span = tracing:: debug_span!( "sync_interval" ) ;
649652 let _enter = sync_span. enter( ) ;
650653
@@ -659,7 +662,8 @@ cfg_sync! {
659662 // `bootstrap_db` (for synced dbs) before calling connect. Otherwise, the sync
660663 // protocol skips calling `export` endpoint causing slowdown in initial bootstrap.
661664 let conn = db. connect( ) ?;
662- let jh = tokio:: spawn(
665+
666+ tokio:: spawn(
663667 async move {
664668 let mut interval = tokio:: time:: interval( sync_interval) ;
665669
@@ -669,21 +673,32 @@ cfg_sync! {
669673 interval. tick( ) . await ;
670674
671675 let mut ctx = sync_ctx. lock( ) . await ;
676+
672677 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+ }
675685 }
676686 } 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+ }
679694 }
680695 }
681696 }
682697 }
683698 . instrument( tracing:: debug_span!( "sync interval thread" ) ) ,
684699 ) ;
685700
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 ) ) ) ) ;
687702 }
688703
689704 Ok ( Database {
0 commit comments