Skip to content

Commit 3fb6771

Browse files
committed
fix: add a check if the res is destroyed before sending response
In the case of using `curl` or a similar tool on the command line, or if the client decides to end the request for a streamed file early without the check we would end up causing a server crash. Now, we will just not send the response as the client has already decided how to move on. fix: nestjs#10105
1 parent 7389070 commit 3fb6771

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

packages/common/file-stream/streamable-file.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isFunction } from '../utils/shared.utils';
44
import { StreamableFileOptions } from './streamable-options.interface';
55

66
export interface StreamableHandlerResponse {
7+
destroyed: boolean;
78
statusCode: number;
89
send: (msg: string) => void;
910
}
@@ -15,8 +16,10 @@ export class StreamableFile {
1516
err: Error,
1617
response: StreamableHandlerResponse,
1718
) => void = (err: Error, res) => {
18-
res.statusCode = 400;
19-
res.send(err.message);
19+
if (!res.destroyed) {
20+
res.statusCode = 400;
21+
res.send(err.message);
22+
}
2023
};
2124

2225
constructor(buffer: Uint8Array, options?: StreamableFileOptions);

0 commit comments

Comments
 (0)