fix(send-idem): reject non-finite dedup ttl - #350
Conversation
send_idem validated the dedup ttl with only a "> 0" check. On PG 17+,
interval 'infinity' passes that check, creating a dedup key that never
expires and is never reaped by maint_idem -- unbounded pgque.idem growth.
Add an isfinite() guard (all overloads reduce to the text overload) so a
non-finite ttl is rejected with a clear message. This makes the docs
contract ("a positive finite interval") true.
Red/green: failing test added to tests/test_send_idem.sql (gated to PG 17+,
where infinite intervals exist), verified failing then green against a
fresh devel install; us13 acceptance stays green. Regenerated the devel
assembly (pgque.sql, pgque-tle.sql).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
samorev Code Review Report
REVIEW FINDINGS (5)HIGH
LOW [guidelines] The error string was rewritten for all three validation branches, not just the new non-finite one, so
LOW [tests] The PR's central safety argument — "all
LOW [tests] On PG < 17 the new test emits a
LOW [bugs] Unverified from the diff — the guard is placed in the
Summary
Note:
Review metadatasamorev-assisted review (AI analysis by Tanya301/samorev) |
Summary
pgque.send_idem()validated the dedup TTL with only a> 0check. OnPostgreSQL 17+,
interval 'infinity'passes that check, creating a dedupkey that never expires and is never reaped by
maint_idem— unboundedpgque.idemtable growth.This adds an
isfinite()guard to the TTL validation (same pattern used byclaim_slot's lease TTL). Allsend_idemoverloads reduce to the textoverload, so the single guard covers both the text and jsonb variants.
The guard makes the documented contract — a dedup TTL must be a positive
finite interval — actually enforced.
Change
devel/sql/pgque-api/send_idem.sql: guard becomesi_ttl is null or i_ttl <= interval '0' or not isfinite(i_ttl), with aclear message:
dedup ttl must be a positive finite interval, got %.devel/sql/pgque.sql,pgque-tle.sql).tests/test_send_idem.sql: new red/green test. Gated to PG 17+, whereinfinite intervals exist (older servers reject the literal at parse time).
Validation
Fresh install of
devel/sql/pgque.sqlon PostgreSQL 18.3.Red (before the fix): the new test fails — the infinite TTL is accepted.
Green (after the fix):
Both suites green on a fresh install:
tests/test_send_idem.sql— 13/13 PASStests/acceptance/us13_producer_idempotency.sql— US-13: PASSEDCommands:
🤖 Generated with Claude Code