Skip to content

http: IncomingMessage does not emit error on premature close #41

Closed
@ronag

Description

@ronag

This is an issue that got stuck in the Node repo due to concerns of breaking the ecosystem. Thought it might be worth a quick look in this group to see whether we find a solution we haven't considered yet?

The problem here is that instead of emitting an ECONNRESET 'error' on the IncomingMessage object we emit 'aborted' which is surprising when the object is sent in a function that expects a regular stream.

function myStreamProcessor(stream, cb) {
  // Stream logic that will deadlock if stream 
  // is an `IncomingMessage` since it does not listen to `'aborted'`
  stream
    .on('error, cb)
    .on('data', /* do something */)
    .on('end', cb)
}

The current workaround, which is probably good enough for most cases, is to encourage usage of pipeline which properly handles/normalizes this issue.

This is not a totally uncommon issue, e.g. I saw it recently at https://github.com/szmarczak/http-timer (3,233,355 weekly downloads) where an 'aborted' listener is missing and instead an 'error' listener is registered.

nodejs/node#28172 (issue)
nodejs/node#28677 (closed proposal PR)

I would recommend a read through of the comments for PR above to understand existing concerns.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions