node.js – How to deploy a SSE node app to Heroku without getting H15 idle connection closed error?


I am using express-sse in my backend (node) and react-native-sse in client (react native). I create a connection for notifications, so whenever one is received its send to specific users. In development it works all fine. When deploying (with Heroku) I keep getting this error:

heroku[router]: at=error code=H15 desc="Idle connection" method=GET path="/notifications_stream" host=myapp.herokuapp.com request_id=5504xxx fwd="79.204xxx" dyno=web.1 connect=0ms service=55003ms status=503 bytes= protocol=https

After researching I found out apparently if there is no data returned during the open connection during 55 seconds, Heroku will close that connection.

However, I’m getting that error immediately and not after 55 seconds.

Ive been researching a lot and the only solution I could find is to ping my server every 55 or less seconds so the connection is not closed. Im not sure how to do it and also if thats the solution as the error comes again immediately.
Any ideas would be very much appreciated!

the route that throws the err is:

const SSE = require("express-sse");
const sse = new SSE(["test"], { isSerialized: false, initialEvent: 'initialize sse' });

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



Source link

Leave a Comment