Skip to content

fix(lakebase): recycle pool connections and pass through dropped pool options - #744

Draft
calvarjorge wants to merge 7 commits into
mainfrom
fix/lakebase-connection-lifetime
Draft

calvarjorge wants to merge 7 commits into
mainfrom
fix/lakebase-connection-lifetime

Conversation

@calvarjorge

@calvarjorge calvarjorge commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Important

CI validation only - do not review or merge. This is a repush of #719 (from a fork), kept at its current head, to run CI with repo secrets: fork runs can't get the OIDC token setup-jfrog-npm needs. Review and merge happen on #719. This PR will be closed once CI finishes.

This pull request and its description were written by Isaac.

billmcmillin and others added 5 commits November 6, 2026 14:00
… options

getLakebasePgConfig() built the pg.Pool config from a fixed list of 11
keys, so maxLifetimeSeconds, application_name, keepAlive, query_timeout
and options were silently dropped. Without a lifetime, pool connections
were never recycled. Access granted through Unity Catalog claims in a
Lakebase OAuth token stops working 4 hours after the token is minted
while the connection stays open, so a busy pool kept failing with
"permission denied" until the app restarted.

- Pass the five options through to pg.Pool, keeping the explicit key
  list.
- Default maxLifetimeSeconds to 1800 (30 minutes); an explicit 0 is
  kept.
- Warn when maxLifetimeSeconds is 0 or above 9000 (2.5 hours): the
  4-hour lapse, less up to an hour of token age at login, less a
  30-minute margin.
- Ignore a negative or non-finite maxLifetimeSeconds, with a warning,
  and use the default. pg-pool would otherwise close every connection
  as soon as it opens (negative) or never recycle (NaN).
- Document maxLifetimeSeconds, including that held clients are only
  recycled on release, and regenerate the API docs.
- Add unit tests for the default, the warnings and the pass-through.
- Add tools/lakebase-soak.ts, a soak harness that runs a real pool
  against a sandbox endpoint and checks connection age, token age at
  login, application_name and table access.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Bill McMillin <bill.mcmillin@databricks.com>
pg-pool passes maxLifetimeSeconds * 1000 to setTimeout. Above 2^31 - 1 ms
(about 24.8 days), Node fires the timer after 1 ms, so every connection
closed after a single use. Treat those values like Infinity: warn and use
the default. Compare in milliseconds so 2147483 s is kept and fractional
values just past the limit are rejected.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Bill McMillin <bill.mcmillin@databricks.com>
The soak harness recorded a Ctrl-C stop as `incomplete` but left it out
of `passed`, so a run stopped after the one-hour token boundary still
passed and exited 0. Add a `ran_full_duration` check so a stopped run
always fails and the summary shows why.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Bill McMillin <bill.mcmillin@databricks.com>
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AppKit PR bot

🔬 Run evals

Start an eval for this PR from the evals-monitor app: Go to Evals Monitor →

📦 Try this PR's app template

Scaffolds a new app from this PR's SDK build. Run it in any folder (requires the GitHub CLI — gh auth login — and the Databricks CLI):

gh run download 45199193883 -R databricks/appkit -n appkit-template-0.102.0-pr.1cb7716-fix-lakebase-connection-lifetime-744 -D appkit-pr-744 \
  && unzip -o "appkit-pr-744/appkit-template-0.102.0-pr.1cb7716-fix-lakebase-connection-lifetime-744.zip" -d "appkit-pr-744" \
  && databricks apps init --template "appkit-pr-744"

The template pins @databricks/appkit and @databricks/appkit-ui to tarballs built from this branch, so the scaffolded app runs against this PR's code.

billmcmillin and others added 2 commits November 23, 2026 09:52
`connections_recycled` only checked that no pool connection outlived the
lifetime, so a run shorter than the lifetime passed without seeing any
connection recycled. Also require the oldest connection to reach the
lifetime, less one interval and the probe slack.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Bill McMillin <bill.mcmillin@databricks.com>
… exec

Under `pnpm exec tsx`, one Ctrl-C reaches the harness as a SIGINT from
the terminal, a SIGTERM from pnpm 1 ms later and a SIGINT relayed by tsx
30 ms after that. The harness had no SIGTERM handler, so pnpm's SIGTERM
killed it before it wrote a summary, and `ran_full_duration` never ran.
Treat SIGTERM like SIGINT, and signals within a second of the first as
the same stop request; only a later signal quits immediately.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Bill McMillin <bill.mcmillin@databricks.com>

This branch has not been deployed

No deployments
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.

2 participants