Skip to content

event emitter memory leak on flush #3529

@usernameisalreadytaken2014

Description

I'm using SSE streams to push JSON events to a web browser.

There is a res.flush() after every bundle of SSE data, to make sure the client gets data.

(Every 15 seconds there's also a keep-alive function that sends a ": keep-alive\n" comment over the channel, along with a res.flush(), to keep stateful firewalls from closing the TCP connection while the browser window showing graphs etc. is open.)

Also using require('compression'), since the SSE streams are usually heavy with data in the beginning before then slowing down.

For some reason, res.flush() causes an error from node:

(node) warning: possible EventEmitter memory leak detected. 11 drain listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Gzip.addListener (events.js:239:17)
    at Gzip.Readable.on (_stream_readable.js:665:33)
    at Gzip.once (events.js:265:8)
    at Gzip.Zlib.flush (zlib.js:448:10)
    at ServerResponse.flush (compression/index.js:70:16)
    at null._repeat (sample.js:2:8)
    at wrapper [as _onTimeout] (timers.js:264:19)
    at Timer.listOnTimeout (timers.js:92:15)

I couldn't find response.flush() documented in the v4.2.1 NodeJS documentation, so I might be calling it incorrectly?

As far as I could read from the compression module documentation, I'm using it correctly though..

According to the folks over at compression, this is not a bug in the compression library, but in nodejs:
expressjs/compression#58 (comment)

What is your opinion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    eventsIssues and PRs related to the events subsystem / EventEmitter.zlibIssues and PRs related to the zlib subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions