Server sent event generates error ERR_INCOMPLETE_CHUNKED_ENCODING

Viewed 164

I have ExpressJS server (in NodeJS), which uses server sent event to announce changes at server database.

Actual handler in my NodeJS app seems like this:

this._app.use((req, res, next) => {
    if (req.url.includes("addDBListener")) {
        res.writeHead(200, {
            'Content-Type': 'text/event-stream',
            'Cache-Control': 'no-cache',
            'Connection': 'keep-alive'
        });
        res.write('\n\n');
        let path = (req.query && req.query.path) ? req.query.path : "";
        this.dbListeners.push({
           path: path,
           res: res
        });
    }
    else {
        next();
    }
});

Then, when any changes in database happens, I send info to clients this way ("i" is index of client, to which I send new info):

this.clientDBListeners[i].res.write("data: " + JSON.stringify(DBPart) + "\n\n");

At client side, I have this to init (and process) event handling:

source = new EventSource('/addDBListener?path=' + dbPath)

let messageHandler = (e)=> {
    console.log("DATAA: "+e.data);
}

let errorHandler = (e)=> { 
    //process error
    console.log("ERROR!!!");
}

source.addEventListener('message', messageHandler);
source.addEventListener('error',  errorHandler)

Entire code works, I get updates from server correctly etc... But one strange thing is, that I get "weird" error in Google chrome console every about 2.5 minutes (So after hour is console full of errors)... And I really don't know why.

Error looks like this:
Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING
OR
GET http://192.168.1.4/addDBListener?path=/rooms/ net::ERR_INCOMPLETE_CHUNKED_ENCODING 200 (OK)

First one is shown one time at client start, second one is repeatedly happening, see image:
enter image description here

From server I send message with appended "\n\n" and Connection: keep-alive, so I really don't know, where is problem...

Thanks!

0 Answers
Related