Skip to content

SpacetimeDB daemon panics and crashes on updating a module re-creating the same index #2761

@egormanga

Description

@egormanga

Setup:

#[table(name=user)]
struct User {
	#[primary_key]
	id: Identity,

	#[unique]
	username: String,
}

#[table(name=thing)]
struct Thing {
	#[primary_key]
	#[auto_inc]
	id: u64,

	#[index(btree)]
	owner: Identity,
}

Logs:

INFO crates/core/src/db/update.rs:143: Creating index `thing_owner_idx_btree` on table `thing`
thread 'tokio-runtime-worker' panicked at crates/table/src/table.rs:1790:14:
called `Option::unwrap()` on a `None` value
stack backtrace:
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic
   3: core::option::unwrap_failed
   4: spacetimedb_table::table::UniqueConstraintViolation::build
   5: spacetimedb::db::datastore::locking_tx_datastore::mut_tx::MutTxId::create_index::{{closure}}
   6: spacetimedb::db::datastore::locking_tx_datastore::mut_tx::MutTxId::create_index
   7: spacetimedb::db::update::update_database
   8: <spacetimedb::host::wasm_common::module_host_actor::WasmModuleInstance<T> as spacetimedb::host::module_host::ModuleInstance>::update_database
   9: <spacetimedb::host::module_host::AutoReplacingModuleInstance<T> as spacetimedb::host::module_host::ModuleInstance>::update_database
  10: spacetimedb::host::module_host::ModuleHost::call::{{closure}}::{{closure}}
  11: tokio::runtime::task::core::Core<T,S>::poll
  12: tokio::runtime::task::harness::Harness<T,S>::poll
  13: tokio::runtime::scheduler::multi_thread::worker::Context::run_task
  14: tokio::runtime::scheduler::multi_thread::worker::Context::run
  15: tokio::runtime::context::scoped::Scoped<T>::set
  16: tokio::runtime::context::runtime::enter_runtime
  17: tokio::runtime::scheduler::multi_thread::worker::run
  18: <tokio::runtime::blocking::task::BlockingTask<T> as core::future::future::Future>::poll
  19: tokio::runtime::task::core::Core<T,S>::poll
  20: tokio::runtime::task::harness::Harness<T,S>::poll
  21: tokio::runtime::blocking::pool::Inner::run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Steps to reproduce:

  1. Publish a module as specified above;
  2. Create two thing table entries with the same owner value;
  3. Comment out the index annotation on the owner field;
  4. Publish (update) the module;
  5. Uncomment the annotation back;
  6. Try to publish the module again.

At this point, the whole database process crashes with a panic.

Removing either User or the unique annotation in it fixes the problem.

Speculation:

Apparently, the index (or its contents, somehow) doesn't get fully deleted when it should, causing a collision on subsequent creation.
Or, maybe, it's being mistakingly implicitly treated as unique for some reason (leaked state in the macro from above in User?).

Perhaps, related to #1525?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions