Skip to content

Fix block_on usage in connect #2033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions libsql/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,17 +682,20 @@ impl Database {
};
use tokio::sync::Mutex;

let _ = tokio::task::block_in_place(move || {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
rt.block_on(async {
if let Some(sync_ctx) = &db.sync_ctx {
let sync_ctx_clone = sync_ctx.clone();
std::thread::spawn(move || {
let rt = tokio::runtime::Runtime::new().unwrap();
// we will ignore if any errors occurred during the bootstrapping the db,
// because the client could be offline when trying to connect.
let _ = db.bootstrap_db().await;
rt.block_on(async {
let mut locked_ctx = sync_ctx_clone.lock().await;
let _ = crate::sync::bootstrap_db(&mut locked_ctx).await;
});
})
});
.join()
.expect("thread panicked while bootstrapping the db");
}

let local = db.connect()?;

Expand Down
Loading