ReviewOS

stacks/bun-query-builder

Connection cache ignores host/port/url/pool changes after setConfig (no resetConnection)

#1041
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

getOrCreateBunSql only rebuilds when dialect or database.database changes. Changing host, port, username, password, url, or pool via setConfig does not invalidate the cached connection, and setConfig never calls resetConnection. Callers must know to call resetConnection() manually — undocumented at the setConfig boundary.

Location

src/db.ts:~469-483; setConfig in src/config.ts:~160.

Suggested fix

Key the cache on the full resolved connection string + pool options, or have setConfig call resetConnection() when any database.* field changes.

Severity: medium. Found via internal code audit.

9 days ago

Fixed in c5d4457. getOrCreateBunSql now keys its cache on a full connectionSignature() (dialect + every database.* field — database/username/password/host/port/url — plus resolved pool options) instead of just dialect + database name, so changing host/port/url/credentials/pool via setConfig invalidates the cached connection. Regression test added; full suite green.

Sign in to comment on this issue.