Skip to content

http client error events might be suppressed #318

@Flarna

Description

@Flarna

I think this check in http_p.js should be improved as it may result in not re-emitting an error event.

this._events.error is either an Array (if more then 1 listener is installed) or Function (only 1 listener installed).
Currently this check works because the installed listener errorCapturer has exactly 1 named parameter therefore errorCapturer.length === 1.
But if there is a module used which wraps the installed listeners (e.g. for CLS,...) or if once is used to install the listener this is broken. Besides that it relies on internals of EventEmitter (the _events field`).

I recommend to use the public EventEmitter Api to check that <= 1 listener is installed.

Recent NodeJs versions allow to listen on errorMonitor to avoid the need to re-emit in case only 1 listener is present at all.

Edit:
Found that also postgres and mysql is effected.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions