express-sse icon indicating copy to clipboard operation
express-sse copied to clipboard

DeprecationWarning: OutgoingMessage.flush is deprecated.

Open digi-chris opened this issue 4 years ago • 8 comments

Using the latest version of Node, I'm getting the following warning when a client is connected to the SSE endpoint and a server event is sent:

(node:16688) [DEP0001] DeprecationWarning: OutgoingMessage.flush is deprecated. Use flushHeaders instead.

I think this is likely related to commit 96723a006760e93e6bb2a5fbad53da744951c586, which added res.flush() after the message is sent.

digi-chris avatar Apr 28 '20 09:04 digi-chris

I've removed the res.flush() when I'm using it, and have instead set the compression module to ignore SSE. Not sure if it's worth removing it here and documenting that instead?

  app.use(
    compression({
      filter: (req, res) =>
        !res.getHeaders()["content-type"].includes("text/event-stream"),
    })
  );

cooper667 avatar May 03 '20 09:05 cooper667

@cooper667, the more general solution would be to include no-transform in the Cache-Control header. Not only does compression respect that directive but any proxy between client and server, too. Unfortunately, this package hardcodes the header value to no-cache.

apparebit avatar Jun 19 '20 17:06 apparebit

In recent node, express-sse doesn't work at all for this reason.

kirushyk avatar Sep 05 '20 10:09 kirushyk

same problem here. seems incompatible. node just crashes

damnms avatar Oct 20 '20 10:10 damnms

Looks like there is already a pull request out there to handle no-transform. https://github.com/dpskvn/express-sse/pull/31 Now, we just need to fix the flush().

bradisbell avatar Nov 20 '20 21:11 bradisbell

It seems that there is not so much activity here right now. For people that are still looking for a solution for the res.flush() problem (TypeError: res.flush is not a function) and are not using the compression middleware for express.js. You can create a simple middleware function for express that adds the function.

The following piece of code could maybe help some people:

app.use(function (req, res, next) {
  res.flush = function () { /* Do nothing */ }
  next();
})

This adds the empty function to res object and express-sse will not crash anymore. You can also just downgrade your express-sse package in package.json and set it fixed to 0.5.1 for now. The other solution is to start using another package. But mostly this requires modifying existing code.

This pull request would solve the problem i think. https://github.com/dpskvn/express-sse/pull/29/commits/2f8f08da7cb90fa27fd54d723688fa81aa610316

I hope this helps some people.

wiegvlieg avatar Feb 04 '21 16:02 wiegvlieg

@wiegvlieg , to reduce the workaround affect area, we can do it like this:

app.get('/sse', (req, res, next) => {
  res.flush = () => {}; 
  next();
}, sse.init);

aguegu avatar Apr 03 '21 07:04 aguegu

It seems that there is not so much activity here right now. For people that are still looking for a solution for the res.flush() problem (TypeError: res.flush is not a function) and are not using the compression middleware for express.js. You can create a simple middleware function for express that adds the function.

The following piece of code could maybe help some people:

app.use(function (req, res, next) {
  res.flush = function () { /* Do nothing */ }
  next();
})

This adds the empty function to res object and express-sse will not crash anymore. You can also just downgrade your express-sse package in package.json and set it fixed to 0.5.1 for now. The other solution is to start using another package. But mostly this requires modifying existing code.

This pull request would solve the problem i think. 2f8f08d

I hope this helps some people.

this helped me thanks a lot

Samueloyeks avatar Oct 23 '22 23:10 Samueloyeks