Skip to content

Feat/acquire with timeout - #6

Open
battermann wants to merge 4 commits into
avanov:devfrom
wireapp:feat/acquire-with-timeout
Open

Feat/acquire with timeout#6
battermann wants to merge 4 commits into
avanov:devfrom
wireapp:feat/acquire-with-timeout

Conversation

@battermann

@battermann battermann commented Jul 8, 2026

Copy link
Copy Markdown
  • We added timeout-aware pool acquisition to hasql-resource-pool as a separate API entry point instead of changing the existing use behavior.
  • connAcqTimeout keeps its original meaning: it configures libpq connect_timeout for connection establishment. It is not reused for pool-slot waiting, to avoid conflating two different timeouts.
  • The new API exposes an explicit pool acquisition timeout parameter so callers can decide per call whether checkout should be bounded or unbounded.
  • We kept the existing use / useWithObserver behavior unchanged and added timeout-aware variants for callers that need bounded checkout.
  • We first tried a simple timeout (ResourcePool.takeResource pool) approach, but it did not reliably enforce the timeout in exhausted-pool scenarios.
  • The final implementation mirrors resource-pool’s checkout mechanics and races resource availability against a timeout, which matches the semantics we needed more closely.
  • The implementation is intentionally lower-level because resource-pool does not expose a public “bounded checkout” API.
  • The test was rewritten to avoid relying on a slow SQL query holding the slot. It now blocks the first checkout in the connection getter itself, then verifies that a second checkout returns AcquisitionTimeoutUsageError while the pool is exhausted.
  • This keeps the behavior deterministic and tests the acquisition timeout directly rather than depending on query execution timing.

@battermann
battermann force-pushed the feat/acquire-with-timeout branch from 7846c88 to 209927f Compare July 8, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant