Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deadlock debugging #1243

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/core/src/db/datastore/locking_tx_datastore/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl StateView for TxId {

impl TxId {
pub(crate) fn release(self, ctx: &ExecutionContext) {
log::trace!("RELEASE TX");
record_metrics(ctx, self.timer, self.lock_wait_time, true);
}
}
65 changes: 36 additions & 29 deletions crates/core/src/host/module_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::util::notify_once::NotifyOnce;
use crate::worker_metrics::WORKER_METRICS;
use bytes::Bytes;
use derive_more::{From, Into};
use futures::{Future, FutureExt};
use futures::{Future, FutureExt, TryFutureExt};
use indexmap::IndexMap;
use itertools::{Either, Itertools};
use spacetimedb_client_api_messages::client_api::table_row_operation::OperationType;
Expand All @@ -31,6 +31,7 @@ use spacetimedb_vm::relation::{MemTable, RelValue};
use std::fmt;
use std::sync::{Arc, Weak};
use std::time::{Duration, Instant};
use tokio::task::spawn_blocking;

#[derive(Debug, Clone, From, Into)]
pub struct ProtocolDatabaseUpdate {
Expand Down Expand Up @@ -659,6 +660,7 @@ impl ModuleHost {
.await;
}

#[tracing::instrument(skip_all)]
pub async fn call_identity_connected_disconnected(
&self,
caller_identity: Identity,
Expand All @@ -682,36 +684,41 @@ impl ModuleHost {
reducer_name,
ReducerArgs::Nullary,
)
.await
.map(drop)
.or_else(|e| match e {
// If the module doesn't define connected or disconnected, commit
// an empty transaction to ensure we always have those events
// paired in the commitlog.
//
// This is necessary to be able to disconnect clients after a server
// crash.
ReducerCallError::NoSuchReducer => {
let db = &self.inner.dbic().relational_db;
db.with_auto_commit(
&ExecutionContext::reducer(
db.address(),
ReducerContext {
name: reducer_name.to_owned(),
caller_identity,
caller_address,
timestamp: Timestamp::now(),
arg_bsatn: Bytes::new(),
},
),
|_| anyhow::Ok(()),
)
.ok();

Ok(())
.map_ok(drop)
.or_else(|e| async move {
match e {
// If the module doesn't define connected or disconnected, commit
// an empty transaction to ensure we always have those events
// paired in the commitlog.
//
// This is necessary to be able to disconnect clients after a server
// crash.
ReducerCallError::NoSuchReducer => {
log::trace!("Reducer `{}` not defined, committing empty transaction", reducer_name);
let db = self.inner.dbic().relational_db.clone();
let _ = spawn_blocking(move || {
db.with_auto_commit(
&ExecutionContext::reducer(
db.address(),
ReducerContext {
name: reducer_name.to_owned(),
caller_identity,
caller_address,
timestamp: Timestamp::now(),
arg_bsatn: Bytes::new(),
},
),
|_| anyhow::Ok(()),
)
})
.await;

Ok(())
}
e => Err(e),
}
e => Err(e),
})
.await
}

async fn call_reducer_inner(
Expand Down
Loading