Skip to content

Commit c62973b

Browse files
fix(create-cloudflare): Ensure we exit the process on "SIGINT" and "SIGTERM" (#8243)
Currently C3 does not explicitly exit the process if an error is thrown, or if a "SIGINT" or "SIGTERM" signal is received. This leads to situations when, if `ctrl+C` is pressed while there are still tasks in the stack/microtask queues (think in flight async xhr calls, or polling, or long running `while` loops), the current process will continue running until all those tasks are run to completion, and the queues are empty. This commit fixes this by explicitly calling `process.exit()` when an error is thrown (our internal "SIGINT"/"SIGTERM" handlers will throw a `CancelError`), thus ensuring we always exit the process.
1 parent 968c3d9 commit c62973b

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

.changeset/ripe-socks-stay.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
fix: Ensure we exit the process on "SIGINT" and "SIGTERM"
6+
7+
Currently C3 does not explicitly exit the process if an error is thrown, or if a "SIGINT" or "SIGTERM" signal is received. This leads to situations when, if `ctrl+C` is pressed while there are still tasks in the stack/microtask queues (think in flight async xhr calls, or polling, or long running
8+
`while` loops), the current process will continue running until all those tasks are run to completion, and the queues are empty.
9+
10+
This commit fixes this by explicitly calling `process.exit()` when an error is thrown (our internal "SIGINT"/"SIGTERM" handlers will throw a `CancelError`), thus ensuring we always exit the process.

packages/create-cloudflare/src/cli.ts

+5
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,9 @@ main(process.argv)
201201
})
202202
.finally(async () => {
203203
await reporter.waitForAllEventsSettled();
204+
205+
// ensure we explicitly exit the process, otherwise any ongoing async
206+
// calls or leftover tasks in the stack queue will keep running until
207+
// completed
208+
process.exit();
204209
});

packages/create-cloudflare/src/metrics.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ export function createReporter() {
188188
// Create a new promise that will reject when the user interrupts the process
189189
const cancelDeferred = promiseWithResolvers<never>();
190190
const cancel = async (signal?: NodeJS.Signals) => {
191-
// Let subtasks handles the signals first with a short timeout
191+
// Let subtasks handle the signals first with a short timeout
192192
await setTimeout(10);
193193

194194
cancelDeferred.reject(new CancelError(`Operation cancelled`, signal));

0 commit comments

Comments
 (0)