From 836cd91c37cea8ae58dd04a326435fcb2c88f358 Mon Sep 17 00:00:00 2001 From: Matt Callaway Date: Thu, 31 Oct 2024 13:47:32 +0000 Subject: [PATCH] fix: Destroy the node http server response stream if there was a caught error (#12333) --- .changeset/clean-plums-tap.md | 5 +++++ packages/astro/src/core/app/node.ts | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/clean-plums-tap.md diff --git a/.changeset/clean-plums-tap.md b/.changeset/clean-plums-tap.md new file mode 100644 index 000000000000..010cf1a31824 --- /dev/null +++ b/.changeset/clean-plums-tap.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Destroy the server response stream if async error is thrown diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index b2a60f90ef77..ee9aa0d60c63 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -153,8 +153,10 @@ export class NodeApp extends App { } destination.end(); // the error will be logged by the "on end" callback above - } catch { - destination.end('Internal server error'); + } catch (err) { + destination.write('Internal server error', () => { + err instanceof Error ? destination.destroy(err) : destination.destroy(); + }); } } }