Skip to content

Commit c256c85

Browse files
authored
fix: process should not exit caused when user abort the request (#7550)
1 parent ae00220 commit c256c85

File tree

2 files changed

+7
-5
lines changed
  • packages

2 files changed

+7
-5
lines changed

packages/server/core/src/adapters/node/node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const handleResponseError = (e: unknown, res: NodeResponse) => {
145145
) as Error & {
146146
code: string;
147147
};
148-
if (err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
148+
if (err.code === 'ABORT_ERR' || err.code === 'ERR_STREAM_PREMATURE_CLOSE') {
149149
console.info('The user aborted a request.');
150150
} else {
151151
console.error(e);

packages/toolkit/runtime-utils/src/node/stream.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ class StreamPump {
6363
this.stream.destroy(reason);
6464
}
6565

66-
this.stream.off('data', this.enqueue);
67-
this.stream.off('error', this.error);
68-
this.stream.off('end', this.close);
69-
this.stream.off('close', this.close);
66+
process.nextTick(() => {
67+
this.stream.off('data', this.enqueue);
68+
this.stream.off('error', this.error);
69+
this.stream.off('end', this.close);
70+
this.stream.off('close', this.close);
71+
});
7072
}
7173

7274
enqueue(chunk: Uint8Array | string) {

0 commit comments

Comments
 (0)