Skip to content

Feature/fix pool pagination tenant - #1044

Merged
Mac-5 merged 5 commits into
Synapse-bridgez:mainfrom
Saboleee:feature/fix-pool-pagination-tenant-id
Jul 28, 2026
Merged

Feature/fix pool pagination tenant#1044
Mac-5 merged 5 commits into
Synapse-bridgez:mainfrom
Saboleee:feature/fix-pool-pagination-tenant-id

Conversation

@Saboleee

Copy link
Copy Markdown
Contributor

Summary

This PR fixes 4 related bugs affecting connection pool metrics, pagination stability, and tenant isolation:

Changes

#988 — PaginationParams integer overflow in offset calculation

  • Add validation to clamp page against u32::MAX / page_size
  • Prevents client-controlled DoS via large page numbers in paginated queries
  • Defends against both panic (debug builds) and silent wraparound (release builds)

#985 — idle_count() reports stale connections as available indefinitely

  • Call evict_stale_locked() in idle_count() before returning count
  • Ensures pool health metrics accurately reflect non-stale idle connections
  • Previously, stale connections were only evicted lazily on acquire()

#987 — Transaction list pagination skips and duplicates rows due to ties

  • Add id DESC tie-breaker to ORDER BY clause
  • Guarantees deterministic row ordering when multiple transactions share created_at
  • Fixes classic pagination drift with OFFSET/LIMIT when ties exist

#986 — PostgresTransactionRepository::insert() incompatible with tenant isolation RLS

  • Add tenant_id field to Transaction domain struct
  • Include tenant_id in INSERT statement and SELECT returns
  • Allows RLS policy tenant_isolation_insert to validate tenant context

Notes

  • All fixes are code-only; no schema changes required (tenant_id column already added by migration 20260501)
  • Each fix addresses root causes; no workarounds or band-aids
  • Transaction changes require callers to provide tenant_id when constructing Transaction objects

Closes #985, Closes #986, Closes #987, Closes #988

Saboleee added 4 commits July 27, 2026 17:40
…z#988)

Prevent integer overflow in offset calculation by validating page against
u32::MAX / page_size in PaginationParams::new(). Defends against
client-controlled DoS attacks via large page numbers in paginated queries.
Call evict_stale_locked() before returning idle connection count to ensure
metrics accurately reflect available (non-stale) idle connections rather than
reporting them indefinitely until the next acquire() call.
…bridgez#987)

Add id DESC secondary sort key to ORDER BY clause to provide deterministic
ordering when multiple transactions share the same created_at timestamp.
Prevents row skipping and duplication from OFFSET/LIMIT pagination drift.
…pse-bridgez#986)

Add tenant_id field to Transaction domain struct and update repository to
include it in INSERT and SELECT queries. Allows tenant-aware row-level
security policies to be enforced on transaction inserts.
@drips-wave

drips-wave Bot commented Jul 27, 2026

Copy link
Copy Markdown

@Saboleee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Mac-5
Mac-5 merged commit 9a01167 into Synapse-bridgez:main Jul 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment