You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The "aborted" event is deprecated and states "Deprecated. Listen for 'close' event instead." which isn't related in any way.
The close event fires whenever the stream is CLOSED while the aborted event only fires if the request is ABORTED.
For exmaple a little HTTP-Server:
// server.jsconsthttp=require('http')constserver=http.createServer((request,response)=>{request.on('error',(error)=>{console.error('> THERE WAS AN ERROR',error)})request.on('aborted',()=>{console.log('> REQUEST GOT ABORTED')})request.on('close',()=>{console.log('> REQUEST GOT CLOSED')response.end('CLOSED');})request.resume();// CONSUME ALL DATA});server.on('listening',()=>console.log('HTTP-Server is running.'));server.listen(3100,'127.0.0.1');
And some simple curl requests to this http server: curl -F file=somesmallfile.bin http://127.0.0.1:3100
REQUEST GOT CLOSED
curl -F file=somebigfile.bin --limit-rate 1K http://127.0.0.1:3100 and cancel CTRL+C
REQUEST GOT ABORTEDTHERE WAS AN ERROR Error: aborted at connResetException (node:internal/errors:704:14) at abortIncoming (node:_http_server:680:17) at socketOnClose (node:_http_server:674:3) at Socket.emit (node:events:549:35) at TCP.<anonymous> (node:net:747:14) { code: 'ECONNRESET'}REQUEST GOT CLOSED
As we can see the close event gets triggered in both cases while the abort event only gets triggered in the event of a user interruption. Please clearify this as close isn't an alternative for aborted as stated above.
The text was updated successfully, but these errors were encountered:
I think we can follow the deprecate document and check if it is aborted by request.readableEnded.
consthttp=require('http')constserver=http.createServer((request,response)=>{request.on('error',(error)=>{console.error('> THERE WAS AN ERROR',error)})request.on('close',()=>{if(request.readableEnded){console.log('> REQUEST GOT CLOSED')response.end('CLOSED');}else{console.log('> REQUEST GOT ABORTED')}})request.resume();// CONSUME ALL DATA});server.on('listening',()=>console.log('HTTP-Server is running.'));server.listen(3100,'127.0.0.1');
I assumed that the idea was "don't rely on this code that does cleanup should'nt care if it was closed or aborted" but I concede Robert's intent might have been to check .readableEnded or something similar
Affected URL(s)
https://nodejs.org/api/http.html#class-httpincomingmessage
Description of the problem
The "
aborted
" event is deprecated and states "Deprecated. Listen for 'close' event instead.
" which isn't related in any way.The
close
event fires whenever the stream isCLOSED
while theaborted
event only fires if the request isABORTED
.For exmaple a little HTTP-Server:
And some simple curl requests to this http server:
curl -F file=somesmallfile.bin http://127.0.0.1:3100
REQUEST GOT CLOSED
curl -F file=somebigfile.bin --limit-rate 1K http://127.0.0.1:3100
and cancelCTRL+C
As we can see the close event gets triggered in both cases while the abort event only gets triggered in the event of a user interruption. Please clearify this as
close
isn't an alternative foraborted
as stated above.The text was updated successfully, but these errors were encountered: