From aeaf98b113e512aabda3e7b8560b6d2349aec156 Mon Sep 17 00:00:00 2001 From: alliasgher Date: Tue, 14 Apr 2026 14:31:34 +0500 Subject: [PATCH] fix: catch errors in responseToReadable _read callback The async _read callback in responseToReadable did not wrap reader.read() in a try/catch. If the reader throws (network error, abort, corrupted stream), the rejection was unhandled and could crash the process. Catch the error and call rs.destroy(err) so downstream consumers can handle it gracefully through the stream's error event. Fixes #1443 Signed-off-by: alliasgher --- src/goods.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/goods.ts b/src/goods.ts index 72fb8e8a27..7e5a5ba4df 100644 --- a/src/goods.ts +++ b/src/goods.ts @@ -111,8 +111,12 @@ const responseToReadable = (response: Response, rs: Readable) => { return rs } rs._read = async () => { - const result = await reader.read() - rs.push(result.done ? null : Buffer.from(result.value)) + try { + const result = await reader.read() + rs.push(result.done ? null : Buffer.from(result.value)) + } catch (err) { + rs.destroy(err as Error) + } } return rs }