From 6d2a4150aaf436e7c298c2f81b135743158436fb Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Sun, 9 Jul 2023 11:15:48 +0200 Subject: [PATCH] database: fix an unwrap() in tx_commit It was a legit error -> the transaction doesn't have to be active when commit() is called on it, and the right behavior in that case is to return a TxTerminated error. Fixes https://github.com/penberg/tihku/issues/59 --- core/mvcc/mvcc-rs/src/database/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/mvcc/mvcc-rs/src/database/mod.rs b/core/mvcc/mvcc-rs/src/database/mod.rs index 4bdde3b12..f425e01b1 100644 --- a/core/mvcc/mvcc-rs/src/database/mod.rs +++ b/core/mvcc/mvcc-rs/src/database/mod.rs @@ -515,7 +515,7 @@ impl Database { let end_ts = self.get_timestamp(); // NOTICE: the first shadowed tx keeps the entry alive in the map // for the duration of this whole function, which is important for correctness! - let tx = self.txs.get(&tx_id).unwrap(); + let tx = self.txs.get(&tx_id).ok_or(DatabaseError::TxTerminated)?; let tx = tx.value().write().unwrap(); match tx.state.load() { TransactionState::Terminated => return Err(DatabaseError::TxTerminated),