Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Bug fix.
What is the current behavior?
Fixes #1150
init().end()is declaredend: () => Promise<void>(src/lib/db.ts:73) and isawaited at 65 call sites — 64 insrc/server/routes/*, 1 insrc/lib/generators.ts. It resolves before the pool is closed, because theSentry.startSpan(...)call atsrc/lib/db.ts:250is not returned and the promise wrappingawait _pool.end()is discarded.The other three
Sentry.startSpancall sites in the file —:31,:75,:117— all return their result. The behaviour changed inbf2fad4(14 Apr 2025), which moved the body ofend()inside a span callback; before that commit the method awaited_pool.end()directly.Where it is observable:
pgMeta.*call insrc/server/routes/is awaited, andawait pgMeta.end()follows it — so nothing is in flight whenend()returns early.GET /generators/{typescript,go,swift,python}reachend()throughgetGeneratorMetadata'sfinally(src/lib/generators.ts), which wrapsintrospect()from@supabase/postgrest-typegen.introspect()issues its introspection work as ten concurrent operations on the samePostgresMetainstance under an un-caughtPromise.all.Promise.allrejects on the first rejection, so if one of them fails while the others are still outstanding, thefinallycallsend()on a pool that is not idle — andend()returns before that outstanding work is done.What is the new behavior?
end()resolves after the pool has closed.async end() { - Sentry.startSpan({ op: 'db', name: 'init.end' }, async () => { + return Sentry.startSpan({ op: 'db', name: 'init.end' }, async () => {test/lib/db.tsadds two tests, registered fromtest/index.test.ts:end() resolves only after in-flight queries have finished— startsselect pg_sleep(1)without awaiting it, then races that promise againstdb.end(). Ifend()waits for the pool to drain, the query must settle first. It then confirms viapg_stat_activitythat the connection is gone. No sleeps and no wall-clock assertions.query() after end() runs on a fresh pool—end()setspool = null, so a laterquery()takes theif (!pool)branch atsrc/lib/db.ts:138and builds a temporary pool. This passes before and after the change; it is coverage for the branch nearest the fix, not a second regression test.Before the one-line change:
After:
Additional context
Full suite, macOS on arm64, Node v22.23.2, the
test/dbDocker fixture. One run each.Unmodified
master:With this change:
197 → 199 is the two tests added here; both pass.
query with ssl w/o root certfails identically in both runs — it asserts an anchored regex on Node's TLS error string, and Node on macOS appends a--use-system-cahint that Linux builds do not. The other two failures swapped:test query timeout ...failed on unmodifiedmasterand passed with this change, whiletest js parser error max result ...did the reverse. Both of those assert against the 5-secondPG_QUERY_TIMEOUT_SECSthe suite sets, and both are throughput-sensitive on a laptop.Also run:
npm run check— clean. Note it only coverssrc(tsconfig.jsonhas"include": ["src"]), so it does not type-checktest/lib/db.ts; that is true of every file intest/lib/.npx prettier --check src/lib/db.ts test/lib/db.ts test/index.test.ts— clean.