Cancelling an MPP query waits for a worker's slow filter; a worker that never returns makes the backend uncancellable
What happens?
Cancelling an MPP query does not stop a parallel worker that is waiting anywhere other than the MPP transport. The client gets canceling statement due to user request at once, but the connection can't run its next statement until the worker finishes that wait. If the wait never ends, the backend can't be cancelled or terminated at all; only kill -9 frees it, which resets the cluster.
An MPP worker holds interrupts for its whole fragment execution (HeldInterrupts::hold() at mpp/exec_worker.rs:415, released at line 600), and the leader holds them around each block_on in block_on_next (mpp/interrupt.rs:143). A pending cancel/die is only noticed at the transport's own wait points (PgInterrupt::check in mpp/pg_seams.rs:112, polled by the pull loop and the send spin). Any other wait inside block_on skips every CHECK_FOR_INTERRUPTS(), for example a heap filter calling pg_sleep:
WaitLatch
pg_sleep <- CHECK_FOR_INTERRUPTS() is a no-op here
ExecInterpExpr ... ExecResult <- heap filter
Scanner::try_get_batch_ids
Scanner::next
...
run_mpp_worker <- HeldInterrupts since exec_worker.rs:415The leader services the cancel, then its abort waits for the workers to exit with interrupts held by Postgres itself (DestroyParallelContext: "we can't respond to interrupts at this stage"):
WaitForBackgroundWorkerShutdown
WaitForParallelWorkersToExit
DestroyParallelContext
AtEOXact_Parallel
AbortTransactionInterrupt state read with a debugger 3s after pg_cancel_backend:
| process | InterruptHoldoffCount | ProcDiePending | QueryCancelPending |
|---|---|---|---|
worker in pg_sleep |
1 | 1 (leader's SIGTERM arrived) | 0 |
leader, in DestroyParallelContext |
3 | 0 | 0 (serviced) |
A plain Postgres parallel query running the same filter in a worker is usable again within milliseconds, because the worker dies on the leader's SIGTERM.
The same thing turns into a permanent hang when the worker's wait never ends. Running spilling_buffile_mpp's join with paradedb.spill_to_disk = off, work_mem = 512kB, hash_mem_multiplier = 10 inside a DO ... EXCEPTION block, under CPU load, about 1 run in 20 leaves a surviving worker parked in its block_on after the others fail with Memory Exhausted while SpillPool (DiskManager is disabled). The leader waits in AbortSubTransaction -> DestroyParallelContext forever; pg_cancel_backend and pg_terminate_backend only set QueryCancelPending/ProcDiePending.
The holds come from #5336, which stopped a die from being serviced inside block_on (it proc_exited out of the live runtime). Waits inside block_on that aren't transport wait points still need to see a pending cancel/die.
To Reproduce
Cancels the same join + GROUP BY while a worker is inside the filter's pg_sleep(60), once as an MPP query and once as a plain Postgres parallel query, and prints when the connection runs its next statement.
#!/usr/bin/env bash
PSQL=${PSQL:-psql}
$PSQL -q <<'SQL'
CREATE EXTENSION IF NOT EXISTS pg_search CASCADE;
DROP TABLE IF EXISTS lat_files, lat_pages;
CREATE TABLE lat_files (id serial PRIMARY KEY, title text, content text);
CREATE TABLE lat_pages (id serial PRIMARY KEY, file_id int, size_bytes int);
CREATE INDEX lat_files_idx ON lat_files USING bm25 (id, title, content)
WITH (text_fields = '{"title": {"fast": true}, "content": {}}');
CREATE INDEX lat_pages_idx ON lat_pages USING bm25 (id, file_id, size_bytes)
WITH (numeric_fields = '{"file_id": {"fast": true}, "size_bytes": {"fast": true}}');
SET paradedb.global_mutable_segment_rows = 0;
INSERT INTO lat_files (title, content) SELECT 'file-' || g, 'Section ' || g FROM generate_series(1, 10000) g;
INSERT INTO lat_files (title, content) SELECT 'file-' || g, 'Section ' || g FROM generate_series(10001, 20000) g;
INSERT INTO lat_pages (file_id, size_bytes) SELECT g, g % 4096 FROM generate_series(1, 10000) g;
INSERT INTO lat_pages (file_id, size_bytes) SELECT g, g % 4096 FROM generate_series(10001, 20000) g;
ANALYZE lat_files; ANALYZE lat_pages;
-- The index can't answer this, so it runs per row in the process that scans the row.
CREATE OR REPLACE FUNCTION lat_sleepy(id int) RETURNS bool LANGUAGE plpgsql PARALLEL SAFE AS $$
BEGIN
IF id = 42 THEN PERFORM pg_sleep(60); END IF;
RETURN true;
END $$;
SQL
run() { # run <label> <custom scans on|off> <match predicate>
$PSQL -X -q \
-c "SET application_name = 'lat_$1'" \
-c "SET paradedb.mpp_min_rows = 0; SET max_parallel_workers_per_gather = 2; SET max_parallel_workers = 8;
SET min_parallel_table_scan_size = 0; SET parallel_setup_cost = 0; SET parallel_tuple_cost = 0;
SET parallel_leader_participation = off;
SET paradedb.enable_aggregate_custom_scan = $2; SET paradedb.enable_join_custom_scan = $2" \
-c "SELECT f.title, count(*), sum(p.size_bytes) FROM lat_files f JOIN lat_pages p ON f.id = p.file_id
WHERE $3 AND lat_sleepy(f.id) GROUP BY f.title" \
-c "SELECT 'next statement ran at ' || clock_timestamp()" 2>&1 | grep -E 'ERROR|next statement' &
local client=$!
local pid=
for _ in $(seq 1 300); do
pid=$($PSQL -XAtc "SELECT coalesce(leader_pid, pid) FROM pg_stat_activity WHERE application_name = 'lat_$1' AND wait_event = 'PgSleep'")
[ -n "$pid" ] && break
sleep 0.1
done
[ -n "$pid" ] || { echo "the query never reached pg_sleep"; wait $client; return; }
$PSQL -XAtc "SELECT 'pg_cancel_backend at ' || clock_timestamp() || ': ' || pg_cancel_backend($pid)"
wait $client
}
echo "== MPP (ParadeDB Aggregate Scan)"
run mpp on "f.content @@@ 'Section'"
echo "== plain Postgres parallel query"
run pg off "f.content LIKE 'Section%'"The control uses LIKE so no ParadeDB scan runs in it: with @@@ and the MPP scans off, a Base Scan worker signalled inside its filter hits a separate crash (#6479).
On main:
== MPP (ParadeDB Aggregate Scan)
pg_cancel_backend at 2026-09-27 00:34:12.863843+05:30: true
ERROR: canceling statement due to user request
next statement ran at 2026-09-27 00:35:12.836493+05:30
== plain Postgres parallel query
pg_cancel_backend at 2026-09-27 00:35:12.995477+05:30: true
ERROR: canceling statement due to user request
next statement ran at 2026-09-27 00:35:12.997933+05:3060s vs 2.5ms. I have the same check as an integration test; it fails on main and will come with the fix.
OS:
macOS (aarch64); not OS-specific.
ParadeDB Version (e.g. output of SELECT * FROM paradedb.version_info();):
main (739a11c59); present since #5336 (v0.25.0).
Are you using ParadeDB Docker, Helm, or the extension(s) standalone?
ParadeDB pg_search Extension
Full Name:
Mithun Chicklore Yogendra
Affiliation:
Source: paradedb/paradedb