Skip to content

Commit 47bf462

Browse files
committed
take conn lock before configs lock
1 parent 768998f commit 47bf462

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

libsql-server/src/namespace/meta_store.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,18 @@ impl MetaStore {
495495
pub fn remove(&self, namespace: NamespaceName) -> Result<Option<Arc<DatabaseConfig>>> {
496496
tracing::debug!("removing namespace `{}` from meta store", namespace);
497497

498+
// "configs" lock can be used in both async and sync contexts while "conn" lock always used
499+
// in blocking context
500+
//
501+
// so, we better to acquire "conn" lock first in order to prevent situation when "configs"
502+
// lock is taken but "conn" lock is not free (so, we potentially will block async tasks for
503+
// indefinite amount of time while "conn" lock will be acquired by other thread)
504+
let mut conn = self.inner.conn.blocking_lock();
505+
498506
let mut configs = self.inner.configs.blocking_lock();
499507
let r = if let Some(sender) = configs.get(&namespace) {
500508
tracing::debug!("removed namespace `{}` from meta store", namespace);
501509
let config = sender.borrow().clone();
502-
let mut conn = self.inner.conn.blocking_lock();
503510
let tx = conn.transaction()?;
504511
if config.config.is_shared_schema {
505512
if crate::schema::db::schema_has_linked_dbs(&tx, &namespace)? {

0 commit comments

Comments
 (0)