mirror of
https://github.com/tursodatabase/libsql.git
synced 2025-05-28 06:42:43 +00:00
Stop holding lock during query execution (#1339)
Holding a lock during query execution can lead to a deadlock if the transaction holding it is blocked by another transaction and that other transaction can't proceed because it can't get the lock that is held by the first transaction. Fixes #1290 Signed-off-by: Piotr Jastrzebski <piotr@chiselstrike.com>
This commit is contained in:
committed by
GitHub
parent
d0a0d8a414
commit
777012123d
@ -637,20 +637,24 @@ impl Proxy for ProxyService {
|
||||
}
|
||||
})?;
|
||||
|
||||
let lock = self.clients.upgradable_read().await;
|
||||
let conn = match lock.get(&client_id) {
|
||||
Some(conn) => conn.clone(),
|
||||
None => {
|
||||
tracing::debug!("connected: {client_id}");
|
||||
match connection_maker.create().await {
|
||||
Ok(conn) => {
|
||||
assert!(conn.is_primary());
|
||||
let conn = Arc::new(TimeoutConnection::new(conn));
|
||||
let mut lock = RwLockUpgradableReadGuard::upgrade(lock).await;
|
||||
lock.insert(client_id, conn.clone());
|
||||
conn
|
||||
let conn = {
|
||||
let lock = self.clients.upgradable_read().await;
|
||||
match lock.get(&client_id) {
|
||||
Some(conn) => conn.clone(),
|
||||
None => {
|
||||
tracing::debug!("connected: {client_id}");
|
||||
match connection_maker.create().await {
|
||||
Ok(conn) => {
|
||||
assert!(conn.is_primary());
|
||||
let conn = Arc::new(TimeoutConnection::new(conn));
|
||||
let mut lock = RwLockUpgradableReadGuard::upgrade(lock).await;
|
||||
lock.insert(client_id, conn.clone());
|
||||
conn
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(tonic::Status::new(tonic::Code::Internal, e.to_string()))
|
||||
}
|
||||
}
|
||||
Err(e) => return Err(tonic::Status::new(tonic::Code::Internal, e.to_string())),
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user