Skip to content

Commit

Permalink
fix: Invoke cancel, only if the stream is not closed (#55684)
Browse files Browse the repository at this point in the history
  • Loading branch information
icyJoseph committed Sep 21, 2023
1 parent 4e877c0 commit ea01649
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/src/server/pipe-readable.ts
Expand Up @@ -58,7 +58,7 @@ export async function pipeReadable(
// will also ensure the read promise rejects and frees our resources.
if (!readerDone) {
readerDone = true
reader.cancel().catch(() => {})
if (!reader.closed) reader.cancel().catch(() => {})
}
}
writable.on('close', onClose)
Expand Down Expand Up @@ -88,7 +88,7 @@ export async function pipeReadable(
// If we broke out of the loop because of a client disconnect, and the
// close event hasn't yet fired, we can early cancel.
if (!readerDone) {
reader.cancel().catch(() => {})
if (!reader.closed) reader.cancel().catch(() => {})
}

// If the client hasn't disconnected yet, end the writable so that the
Expand Down

0 comments on commit ea01649

Please sign in to comment.