Repository navigation
fix(drizzle): reject initializing with the connect error and handle it - #18658
Open
Metehan-Bicer wants to merge 1 commit into
Open
Metehan-Bicer wants to merge 1 commit into
Metehan-Bicer wants to merge 1 commit into
Conversation
connect() rejected the adapter's `initializing` promise with no argument and then threw its own error. Only beginTransaction awaits that promise, so a failed connect on a path that opens no transaction surfaced as an unhandledRejection with reason `undefined`. The four SQL adapters now pass the connect error, and a no-op handler is attached wherever the promise is created; connect() still throws and beginTransaction still rejects.
This branch has not been deployed
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?
When
connect()fails on a SQL adapter, it no longer leaves anunhandledRejectionwith reasonundefinedbehind. The adapter'sinitializingpromise now rejects with the connect error and has a handler from the moment it is created.Why?
As described in #18656:
connect()calledrejectInitializing()with no argument and then threw its own error. OnlybeginTransactionawaitsinitializing, so on a request path that opens no transaction nothing handles that rejection. Node reports it as an unhandled rejection whose reason isundefined, with no stack and nothing that points at Payload or the database. The same call is in db-postgres, db-vercel-postgres, db-sqlite and db-d1-sqlite, anddestroycreates a freshinitializingthe same way.How?
Both suggestions from the issue, in all four adapters:
connect()passes the error,rejectInitializing(err), and the type is widened to(err?: unknown) => voidin drizzle's shared types and each adapter's.initializingis created (each adapter'sindex.tsanddrizzle/src/destroy.ts).connect()still throws the real error andbeginTransaction's ownawaitstill rejects, so nothing is swallowed.Tests:
packages/db-postgres/src/connect.spec.ts(new) builds the adapter with apgstub whosePool.connectrejects, then checks that no unhandled rejection is reported and thatinitializingrejects with the connect error. It fails onmain(the listener receivesundefined) and passes with the change. The other three adapters get the identical change; the spec covers db-postgres.test/databasepasses on Postgres and SQLite, and the drizzle and adapter unit specs pass.With the real driver,
getPayloadwithpostgresAdapterpointed at a port with nothing listening:Fixes #18656