Skip to content

http.IncomingMessage aborted Event isn't the same as http.IncomingMessage close Event #43688

@UnlimitedBytes

Description

@UnlimitedBytes

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 is CLOSED while the aborted event only fires if the request is ABORTED.

For exmaple a little HTTP-Server:

// server.js
const http = require('http')

const server = 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 ABORTED
THERE 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions