clockworklabs / clockworklabs/SpacetimeDB

Daemon crash when querying numeric `Vec`s other than `<u8>` over PG Wire

Open
#4,012 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

Setup (v1.11.2):
#[table(name=test)]
struct Test {
	a: Vec<u16>,  // i8 does it as well
}

#[reducer(init)]
fn init(ctx: &ReducerContext) {
	ctx.db.test().insert(Test {
		a: vec![1, 2],
	});
}
Reproduction (via psql):
SELECT * FROM test;
Result:
thread 'tokio-runtime-worker' panicked at pgwire-0.34.2/src/api/results.rs:257:36:
index out of bounds: the len is 6 but the index is 6
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: pgwire::api::results::DataRowEncoder::encode_field
   4: <spacetimedb_pg::encoder::PsqlFormatter as spacetimedb_sats::satn::TypedWriter>::write
   5: spacetimedb_sats::ser::impls::<impl spacetimedb_sats::ser::Serialize for spacetimedb_sats::ValueWithType<spacetimedb_sats::array_value::ArrayValue>>::serialize
   6: spacetimedb_sats::ser::impls::<impl spacetimedb_sats::ser::Serialize for spacetimedb_sats::ValueWithType<spacetimedb_sats::algebraic_value::AlgebraicValue>>::serialize
   7: spacetimedb_pg::pg_server::to_rows
   8: <spacetimedb_pg::pg_server::PgSpacetimeDB<T> as pgwire::api::query::SimpleQueryHandler>::do_query::{{closure}}
   9: pgwire::api::query::SimpleQueryHandler::_on_query::{{closure}}
  10: pgwire::api::query::SimpleQueryHandler::on_query::{{closure}}
  11: spacetimedb_pg::pg_server::start_pg::{{closure}}::{{closure}}
  • Discovered while investigating #3993

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with the Rust schema and the psql query shown, then read pgwire-0.34.2/src/api/results.rs around DataRowEncoder::encode_field and the spacetimedb_pg::encoder::PsqlFormatter path in the stack trace. Check the investigation context in #3993. Done means querying numeric Vecs such as Vec<u16> or Vec<i8> over PG Wire returns rows without a daemon panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, rust
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.