Skip to content

Commit d2d897d

Browse files
committed
fixup! fix(@angular/ssr): settle writeResponseToNodeResponse when client disconnects
1 parent 9b925dd commit d2d897d

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

packages/angular/ssr/node/src/response.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import type { ServerResponse } from 'node:http';
1010
import type { Http2ServerResponse } from 'node:http2';
1111

1212
/**
13-
* Checks whether a Node.js `ServerResponse` or `Http2ServerResponse` is destroyed or closed.
13+
* Checks whether a Node.js `ServerResponse` or `Http2ServerResponse` is destroyed, closed, or ended.
14+
*
15+
* @param destination - The HTTP/1.1 or HTTP/2 server response to check.
16+
* @returns `true` if the response or its underlying stream is destroyed, closed, or ended; otherwise `false`.
1417
*/
1518
function isResponseDestroyedOrClosed(destination: ServerResponse | Http2ServerResponse): boolean {
1619
return (
@@ -106,12 +109,13 @@ export async function writeResponseToNodeResponse(
106109
}
107110

108111
const { done, value } = await reader.read();
109-
if (done || isDestroyedOrClosed()) {
110-
if (!isDestroyedOrClosed()) {
111-
destination.end();
112-
} else {
113-
cancelReader();
114-
}
112+
if (isDestroyedOrClosed()) {
113+
cancelReader();
114+
break;
115+
}
116+
117+
if (done) {
118+
destination.end();
115119
break;
116120
}
117121

0 commit comments

Comments
 (0)