File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -682,17 +682,37 @@ impl Database {
682682 } ;
683683 use tokio:: sync:: Mutex ;
684684
685- let _ = tokio:: task:: block_in_place ( move || {
686- let rt = tokio:: runtime:: Builder :: new_current_thread ( )
687- . enable_all ( )
688- . build ( )
689- . unwrap ( ) ;
690- rt. block_on ( async {
691- // we will ignore if any errors occurred during the bootstrapping the db,
692- // because the client could be offline when trying to connect.
693- let _ = db. bootstrap_db ( ) . await ;
694- } )
695- } ) ;
685+ if let Some ( sync_ctx) = & db. sync_ctx {
686+ let sync_ctx = sync_ctx. clone ( ) ;
687+ // we will ignore if any errors occurred during the bootstrapping the db,
688+ // because the client could be offline when trying to connect.
689+ match tokio:: runtime:: Handle :: try_current ( ) {
690+ Ok ( _) => {
691+ std:: thread:: spawn ( move || {
692+ let rt = tokio:: runtime:: Builder :: new_current_thread ( )
693+ . enable_all ( )
694+ . build ( )
695+ . unwrap ( ) ;
696+ rt. block_on ( async {
697+ let mut locked_ctx = sync_ctx. lock ( ) . await ;
698+ let _ = crate :: sync:: bootstrap_db ( & mut locked_ctx) . await ;
699+ } ) ;
700+ } )
701+ . join ( )
702+ . expect ( "bootstrap thread panicked" ) ;
703+ }
704+ Err ( _) => {
705+ let rt = tokio:: runtime:: Builder :: new_current_thread ( )
706+ . enable_all ( )
707+ . build ( )
708+ . unwrap ( ) ;
709+ rt. block_on ( async {
710+ let mut locked_ctx = sync_ctx. lock ( ) . await ;
711+ let _ = crate :: sync:: bootstrap_db ( & mut locked_ctx) . await ;
712+ } ) ;
713+ }
714+ }
715+ }
696716
697717 let local = db. connect ( ) ?;
698718
You can’t perform that action at this time.
0 commit comments