-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(webapp): stop writer DB connectivity errors leaking to trigger() API clients #3874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d-cs
wants to merge
3
commits into
main
Choose a base branch
from
fix/trigger-writer-db-error-leak
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| area: webapp | ||
| type: fix | ||
| --- | ||
|
|
||
| Stop `trigger()` from leaking raw database connection errors to API clients during a database outage; infrastructure errors now return a generic, retryable 500. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { Prisma } from "@trigger.dev/database"; | ||
|
|
||
| // Prisma connectivity / infrastructure error codes — engine- and | ||
| // connection-level failures, not query- or validation-level ones. When the | ||
| // database is unreachable, Prisma 6.x throws a PrismaClientKnownRequestError | ||
| // carrying one of these codes (e.g. P1001 "Can't reach database server"). | ||
| const INFRASTRUCTURE_PRISMA_CODES = new Set([ | ||
| "P1001", // Can't reach database server | ||
| "P1002", // Database server reached but timed out | ||
| "P1008", // Operations timed out | ||
| "P1017", // Server has closed the connection | ||
| ]); | ||
|
|
||
| /** | ||
| * True when `error` is a Prisma infrastructure/connectivity failure (DB | ||
| * unreachable, timed out, connection dropped) rather than a query- or | ||
| * validation-level error. | ||
| * | ||
| * These errors carry internal infrastructure detail (e.g. the database | ||
| * hostname) in their `.message`, so they must never be surfaced to API | ||
| * clients — callers should let them propagate to the generic 5xx handler | ||
| * (which both scrubs the message and is retryable by the SDK) instead of | ||
| * folding `.message` into a client-facing error. | ||
| */ | ||
| export function isInfrastructureError(error: unknown): boolean { | ||
| if ( | ||
| error instanceof Prisma.PrismaClientInitializationError || | ||
| error instanceof Prisma.PrismaClientRustPanicError || | ||
| error instanceof Prisma.PrismaClientUnknownRequestError | ||
| ) { | ||
| return true; | ||
| } | ||
|
|
||
| if (error instanceof Prisma.PrismaClientKnownRequestError) { | ||
| return INFRASTRUCTURE_PRISMA_CODES.has(error.code); | ||
| } | ||
|
|
||
| return false; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { Prisma } from "@trigger.dev/database"; | ||
| import { isInfrastructureError } from "../app/utils/prismaErrors.js"; | ||
|
|
||
| describe("isInfrastructureError", () => { | ||
| it("treats a P1001 'can't reach database server' (KnownRequestError) as infrastructure", () => { | ||
| // Prisma 6.x reports P1001 as a PrismaClientKnownRequestError with code P1001 — | ||
| // this is the exact production shape that leaked the RDS hostname to a customer. | ||
| const err = new Prisma.PrismaClientKnownRequestError( | ||
| "Invalid `prisma.project.findFirst()` invocation: Can't reach database server at host:5432", | ||
| { code: "P1001", clientVersion: "6.14.0" } | ||
| ); | ||
| expect(isInfrastructureError(err)).toBe(true); | ||
| }); | ||
|
|
||
| it("treats a PrismaClientInitializationError as infrastructure", () => { | ||
| const err = new Prisma.PrismaClientInitializationError("init failed", "6.14.0"); | ||
| expect(isInfrastructureError(err)).toBe(true); | ||
| }); | ||
|
|
||
| it("does NOT treat a query/validation error (P2002 unique constraint) as infrastructure", () => { | ||
| const err = new Prisma.PrismaClientKnownRequestError("Unique constraint failed", { | ||
| code: "P2002", | ||
| clientVersion: "6.14.0", | ||
| }); | ||
| expect(isInfrastructureError(err)).toBe(false); | ||
| }); | ||
|
|
||
| it("does NOT treat a plain domain Error as infrastructure", () => { | ||
| expect(isInfrastructureError(new Error("Project not found."))).toBe(false); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 Non-infrastructure Prisma errors (e.g. P2002) still have their message forwarded to clients via ServiceValidationError
If
getDefaultWorkerGroupForProjectthrows a non-infrastructurePrismaClientKnownRequestError(e.g. P2002 unique constraint violation), it will still be wrapped inServiceValidationError(error.message)on line 409 and returned to the API client with its raw Prisma message. These messages typically don't contain hostnames or connection strings, so the security risk is lower than infrastructure errors. However, they could still expose internal schema details (table names, constraint names). This is a pre-existing pattern — the PR is specifically scoped to the infrastructure error leak that was observed in production. A broader fix could wrap all non-domain Prisma errors generically, but that's a separate concern.Was this helpful? React with 👍 or 👎 to provide feedback.