Skip to content

Commit 3ce4d85

Browse files
authored
Log instead of panicking when missing a row from st_client (#2722)
1 parent 2699c03 commit 3ce4d85

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

crates/core/src/db/datastore/locking_tx_datastore/mut_tx.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,21 +1244,30 @@ impl MutTxId {
12441244
self.insert_via_serialize_bsatn(ST_CLIENT_ID, row).map(|_| ())
12451245
}
12461246

1247-
pub(crate) fn delete_st_client(&mut self, identity: Identity, connection_id: ConnectionId) -> Result<()> {
1247+
pub(crate) fn delete_st_client(
1248+
&mut self,
1249+
identity: Identity,
1250+
connection_id: ConnectionId,
1251+
database_identity: Identity,
1252+
) -> Result<()> {
12481253
let row = &StClientRow {
12491254
identity: identity.into(),
12501255
connection_id: connection_id.into(),
12511256
};
1252-
let ptr = self
1257+
if let Some(ptr) = self
12531258
.iter_by_col_eq(
12541259
ST_CLIENT_ID,
12551260
col_list![StClientFields::Identity, StClientFields::ConnectionId],
12561261
&AlgebraicValue::product(row),
12571262
)?
12581263
.next()
1259-
.expect("the client should be connected")
1260-
.pointer();
1261-
self.delete(ST_CLIENT_ID, ptr).map(drop)
1264+
.map(|row| row.pointer())
1265+
{
1266+
self.delete(ST_CLIENT_ID, ptr).map(drop)
1267+
} else {
1268+
log::error!("[{database_identity}]: delete_st_client: attempting to delete client ({identity}, {connection_id}), but no st_client row for that client is resident");
1269+
Ok(())
1270+
}
12621271
}
12631272

12641273
pub(crate) fn insert_via_serialize_bsatn<'a, T: Serialize>(

crates/core/src/host/module_host.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ impl ModuleHost {
677677
.replica_ctx()
678678
.relational_db
679679
.with_auto_commit(workload, |mut_tx| {
680-
mut_tx.delete_st_client(caller_identity, caller_connection_id)
680+
mut_tx.delete_st_client(caller_identity, caller_connection_id, self.info.database_identity)
681681
})
682682
.inspect_err(|e| {
683683
log::error!(

crates/core/src/host/wasm_common/module_host_actor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ impl<T: WasmInstance> WasmModuleInstance<T> {
558558
Ok(Ok(())) => {
559559
let res = match reducer_def.lifecycle {
560560
Some(Lifecycle::OnConnect) => tx.insert_st_client(caller_identity, caller_connection_id),
561-
Some(Lifecycle::OnDisconnect) => tx.delete_st_client(caller_identity, caller_connection_id),
561+
Some(Lifecycle::OnDisconnect) => {
562+
tx.delete_st_client(caller_identity, caller_connection_id, database_identity)
563+
}
562564
_ => Ok(()),
563565
};
564566
match res {

0 commit comments

Comments
 (0)