From 20bc193da03b345b23d9aae01a584de3e598eb92 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Thu, 28 Mar 2024 03:37:32 +0000 Subject: [PATCH] fix: reject promise on file stream error when writing heap snapshot (#6603) --- packages/beacon-node/src/util/profile.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/src/util/profile.ts b/packages/beacon-node/src/util/profile.ts index 9c130d7a1eb..7085c329c82 100644 --- a/packages/beacon-node/src/util/profile.ts +++ b/packages/beacon-node/src/util/profile.ts @@ -41,7 +41,11 @@ export async function writeHeapSnapshot(prefix: string, dirpath: string): Promis const snapshotStream = v8.getHeapSnapshot(); const filepath = `${dirpath}/${prefix}_${new Date().toISOString()}.heapsnapshot`; const fileStream = fs.createWriteStream(filepath); - return new Promise((resolve) => { + return new Promise((resolve, reject) => { + fileStream.on("error", (err) => { + reject(err); + }); + snapshotStream.pipe(fileStream); snapshotStream.on("end", () => { resolve(filepath);