#6489·paradedb

Backend hangs forever on exit when terminated while loading a tokenizer typmod

Author: mithuncyCreated Sep 25, 2026Updated Sep 29, 2026
Labelsbugpriority-highuser-request

What happens?

A backend terminated while loading a tokenizer typmod can hang forever instead of exiting. It logs FATAL: terminating connection due to administrator command, then stays active in pg_stat_activity and keeps its locks. Another pg_terminate_backend doesn't help; only kill -9 does, which resets the cluster.

load_typmod (pg_search/src/api/tokenizers/typmod/mod.rs:500) holds the CACHE mutex (line 508) across its SPI lookup (line 514), and each cache miss registers an Abort callback that locks the same mutex (line 539). A FATAL inside that SPI call on a later miss exits without unwinding, so the guard is never dropped. proc_exit -> ShutdownPostgres -> AbortTransaction then runs the earlier miss's callback, which waits on a lock held by a frame that will never return:

parking_lot::raw_mutex::RawMutex::lock_slow
pg_search::api::tokenizers::typmod::load_typmod::{closure}   <- Abort callback
pgrx::callbacks::register_xact_callback::callback
AbortTransaction
AbortOutOfAnyTransaction
ShutdownPostgres
shmem_exit
proc_exit

save_typmod (line 547) has the same pattern (lock 558, SPI 565/593, callback 596); reproduced with two new typmods in one statement.

Any bm25 index with more than one typmod field is exposed: a new backend's first query loads each typmod through SPI. ERROR (cancel, statement_timeout) is not affected because it unwinds and drops the guard; parallel workers are not affected because they fire XACT_EVENT_PARALLEL_ABORT.

To Reproduce

Terminates a new backend at random points while its first query loads 30 typmods, and reports any backend still alive 3s later.

bash
#!/usr/bin/env bash
PSQL=${PSQL:-psql}

cols=$(for i in $(seq 1 30); do printf ", (body::pdb.simple('alias=f%d'))" "$i"; done)
$PSQL -q <<SQL
CREATE EXTENSION IF NOT EXISTS pg_search;
DROP TABLE IF EXISTS typmod_hang;
CREATE TABLE typmod_hang (id bigserial PRIMARY KEY, body text);
CREATE INDEX typmod_hang_idx ON typmod_hang USING bm25 (id $cols);
INSERT INTO typmod_hang (body) VALUES ('hello world');
SQL

hung=0
for i in $(seq 1 30); do
  delay_ms=$((RANDOM % 35))
  $PSQL -X -q -c "SET application_name = 'typmod_hang_$i'" -c "SELECT pg_sleep(0.3)" \
    -c "SELECT count(*) FROM typmod_hang WHERE id @@@ paradedb.all()" >/dev/null 2>&1 &
  client=$!
  until pid=$($PSQL -XAtc "SELECT pid FROM pg_stat_activity WHERE application_name = 'typmod_hang_$i' AND query LIKE 'SELECT pg_sleep%'") && [ -n "$pid" ]; do :; done
  $PSQL -XAtc "SELECT pg_sleep(greatest(0, extract(epoch FROM query_start + interval '300 ms' + interval '1 ms' * $delay_ms - clock_timestamp()))) FROM pg_stat_activity WHERE pid = $pid" \
    -c "SELECT pg_terminate_backend($pid)" >/dev/null
  sleep 3
  state=$($PSQL -XAtc "SELECT state FROM pg_stat_activity WHERE pid = $pid")
  if [ -n "$state" ]; then
    hung=$((hung + 1))
    echo "attempt $i: backend $pid is still '$state' 3s after pg_terminate_backend"
    kill "$client"
  fi
  wait "$client" 2>/dev/null
done
echo "hung backends: $hung / 30"

On main:

attempt 2: backend 43128 is still 'active' 3s after pg_terminate_backend
attempt 23: backend 43529 is still 'active' 3s after pg_terminate_backend
hung backends: 2 / 30

To hit it every time: in a debugger, stop a new backend at its second _SPI_execute_plan while it runs the query, set ProcDiePending = 1 and InterruptPending = 1, and continue.

Possible fix: don't hold CACHE across SPI (look up, drop the guard, run SPI, lock again to insert).

OS:

macOS (aarch64); not OS-specific.

ParadeDB Version (e.g. output of SELECT * FROM paradedb.version_info();):

main (bdf1132ca); present since tokenizers-as-types (#3290, v0.19.0).

Are you using ParadeDB Docker, Helm, or the extension(s) standalone?

ParadeDB pg_search Extension

Full Name:

Mithun Chicklore Yogendra

Affiliation: