Skip to content

fix request abort for node 16+#1580

Open
Matt-Esch wants to merge 1 commit intohttp-party:masterfrom
Matt-Esch:me-fix-abort
Open

fix request abort for node 16+#1580
Matt-Esch wants to merge 1 commit intohttp-party:masterfrom
Matt-Esch:me-fix-abort

Conversation

@Matt-Esch
Copy link
Copy Markdown

After upgrading to node 16, the web proxy stopped working when requests were aborted. The specific use case was SSE where the incoming request has ended but the server response is a long lived http connection. The 'aborted' event and the 'abort' method are deprecated. The response 'close' event and the 'destroy' method are the correct alternatives and pre-date node 8, which is the minimum version this package currently supports. I did run tests on node 8/10/12/14/16 and they failed on node 16 prior to this fix and all pass after this fix.

likev added a commit to likev/node-http-proxy that referenced this pull request Feb 23, 2023
@anthonyalayo
Copy link
Copy Markdown

Can we merge this?

@callumgare
Copy link
Copy Markdown

callumgare commented May 12, 2023

Unfortunately won't work in node.js 16 and below since the "close" event was added to in v16:

https://nodejs.org/docs/latest-v16.x/api/http.html#event-close
https://nodejs.org/docs/latest-v15.x/api/http.html#event-close

Can't find any info on what's the minimum node version node-http-proxy supports but in this case it should be pretty easy to use "abort" for v15 and below and "close" for v16 and above. That's what #1559 does

@gdrbyKo1
Copy link
Copy Markdown

@callumgare I'm not sure I follow. This PR attaches a "close" event listener to res, which is an instance of http.ServerResponse. According to Node.js docs, this event is present in both v16 and v15:
https://nodejs.org/docs/latest-v16.x/api/http.html#event-close_2
https://nodejs.org/docs/latest-v15.x/api/http.html#http_event_close_1
Am I missing something?

pi0 added a commit to unjs/httpxy that referenced this pull request Mar 25, 2026
…ed")`

Replace deprecated `proxyReq.abort()` with `proxyReq.destroy()` and remove
redundant `req.on("aborted")` listener that was broken on Node 16+.
The `res.on("close")` handler already covers client disconnect cleanup.

Upstream: http-party/node-http-proxy#1580
pi0 added a commit to unjs/httpxy that referenced this pull request Mar 25, 2026
…ed")` (#107)

Replace deprecated `proxyReq.abort()` with `proxyReq.destroy()` and remove
redundant `req.on("aborted")` listener that was broken on Node 16+.
The `res.on("close")` handler already covers client disconnect cleanup.

Upstream: http-party/node-http-proxy#1580
@pi0
Copy link
Copy Markdown

pi0 commented Mar 25, 2026

This issue has been fixed in unjs/httpxy#107.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants