Skip to content

Commit ab03163

Browse files
authored
fix(db-*): do not exit process on error during connect (#14647)
This PR removes `process.exit(1)` from our exception handlers within db connect methods. When a connection error occurred in vercel fluid compute, it ungracefully shut down the entire compute process. By re-throwing the error instead, [vercel is able to gracefully handle the error](https://vercel.com/changelog/improved-unhandled-node-js-errors-in-fluid-compute) without shutting down concurrent requests running on the same compute instance. process.exit(1) [was initially added by this commit](f3fee34#r169957812), however noone was able to recall why it was added.
1 parent 9f55254 commit ab03163

File tree

7 files changed

+11
-11
lines changed

7 files changed

+11
-11
lines changed

packages/db-d1-sqlite/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const connect: Connect = async function connect(
5151
this.rejectInitializing()
5252
}
5353
console.error(err)
54-
process.exit(1)
54+
throw new Error(`Error: cannot connect to SQLite: ${message}`)
5555
}
5656

5757
// Only push schema if not in production

packages/db-mongodb/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,6 @@ export const connect: Connect = async function connect(
108108
err,
109109
msg,
110110
})
111-
process.exit(1)
111+
throw new Error(`Error: cannot connect to MongoDB: ${msg}`)
112112
}
113113
}

packages/db-postgres/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export const connect: Connect = async function connect(
108108
if (typeof this.rejectInitializing === 'function') {
109109
this.rejectInitializing()
110110
}
111-
process.exit(1)
111+
throw new Error(`Error: cannot connect to Postgres: ${err.message}`)
112112
}
113113

114114
await this.createExtensions()

packages/db-sqlite/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export const connect: Connect = async function connect(
3636
if (typeof this.rejectInitializing === 'function') {
3737
this.rejectInitializing()
3838
}
39-
process.exit(1)
39+
throw new Error(`Error: cannot connect to SQLite: ${message}`)
4040
}
4141

4242
// Only push schema if not in production

packages/db-vercel-postgres/src/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const connect: Connect = async function connect(
9090
if (typeof this.rejectInitializing === 'function') {
9191
this.rejectInitializing()
9292
}
93-
process.exit(1)
93+
throw new Error(`Error: cannot connect to Postgres: ${err.message}`)
9494
}
9595

9696
await this.createExtensions()

packages/drizzle/src/transactions/beginTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const beginTransaction: BeginTransaction = async function beginTransactio
5959
}
6060
} catch (err) {
6161
this.payload.logger.error({ err, msg: `Error: cannot begin transaction: ${err.message}` })
62-
process.exit(1)
62+
throw new Error(`Error: cannot begin transaction: ${err.message}`)
6363
}
6464

6565
return id

packages/payload/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,12 +1133,12 @@ export const getPayload = async (
11331133
return cached.payload
11341134
}
11351135

1136-
if (!cached.promise) {
1137-
// no need to await options.config here, as it's already awaited in the BasePayload.init
1138-
cached.promise = new BasePayload().init(options)
1139-
}
1140-
11411136
try {
1137+
if (!cached.promise) {
1138+
// no need to await options.config here, as it's already awaited in the BasePayload.init
1139+
cached.promise = new BasePayload().init(options)
1140+
}
1141+
11421142
cached.payload = await cached.promise
11431143

11441144
if (

0 commit comments

Comments
 (0)