Skip to content

Commit

Permalink
remove socket listeners on “abort” (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Brophy <[email protected]>
  • Loading branch information
donavon and brophdawg11 authored Aug 1, 2023
1 parent 3e4d588 commit 5d1e12a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-steaks-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/web-fetch": patch
---

Remove socket listeners if request is aborted
7 changes: 5 additions & 2 deletions packages/fetch/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,13 @@ function fixResponseChunkedTransferBadEnding(request, errorCallback) {
socket.prependListener('close', onSocketClose);
socket.on('data', onData);

request.on('close', () => {
const removeSocketListeners = () => {
socket.removeListener('close', onSocketClose);
socket.removeListener('data', onData);
});
}

request.on('close', removeSocketListeners);
request.on('abort', removeSocketListeners);
});
}

Expand Down

0 comments on commit 5d1e12a

Please sign in to comment.