Skip to content

Commit 5523234

Browse files
committed
fix deadlock
If the connection blocks for some reason while holding the lock, then acquire the lock for config may block, and dealock the runtime.
1 parent 5cfdd70 commit 5523234

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

libsql-server/src/connection/legacy.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ where
380380
ctx: RequestContext,
381381
builder: B,
382382
) -> Result<B> {
383-
let config = self.inner.lock().config();
383+
let inner = self.inner.clone();
384+
let config = tokio::task::spawn_blocking(move || inner.lock().config())
385+
.await
386+
.unwrap();
384387
check_program_auth(&ctx, &pgm, &config).await?;
385388
let conn = self.inner.clone();
386389
CoreConnection::run_async(conn, pgm, builder).await

libsql-server/src/connection/libsql.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ impl LibsqlConnection {
9393
ctx: RequestContext,
9494
builder: B,
9595
) -> Result<B> {
96-
let config = self.inner.lock().config();
96+
let inner = self.inner.clone();
97+
let config = tokio::task::spawn_blocking(move || inner.lock().config())
98+
.await
99+
.unwrap();
97100
check_program_auth(&ctx, &pgm, &config).await?;
98101
let conn = self.inner.clone();
99102
CoreConnection::run_async(conn, pgm, builder).await

0 commit comments

Comments
 (0)