EventSource icon indicating copy to clipboard operation
EventSource copied to clipboard

Type Error: network error

Open monstrum opened this issue 4 years ago • 7 comments

I got Type Error: network error on my console. Whenever I refresh the browser.

This error come from line 913 https://github.com/Yaffle/EventSource/blob/64914d6f12f46e730e9ffd36dd1df1d28437de8b/src/eventsource.js#L913

I am not sure what cause this error. But I tried, commenting this line. The error then gone. Is there anyway to change this behaviour?

Bildschirmfoto 2021-10-21 um 16 03 33

This error can be reproduce on Chrome and also on Firefox. If we can configure, how we handle this error, it would be nice. I suspect this error were thrown by the browser. We can't change how the browser behave, but we can at least decided how to handle this error.

Chrome Version 94.0.4606.81 event-source-polyfill: "1.0.25" Error: Type Error: network error SSE Server: Mercure Rocks v0.10.3

Firefox Version 91.0 event-source-polyfill: "1.0.25" Error: TypeError: Error in body stream SSE Server: Mercure Rocks v0.10.3

monstrum avatar Oct 21 '21 14:10 monstrum

Also happens to me as well, do you have any workarounds?

botjaeger avatar Jun 27 '22 10:06 botjaeger

Same here...any workarounds?

leik-software avatar Jul 20 '22 06:07 leik-software

Nothing yet?

felicandalc avatar Jul 25 '22 18:07 felicandalc

same issue here. network error occurs in readNextChunk method.

var readNextChunk = function readNextChunk() {
  reader.read().then(function(result) {
      if (result.done) {
          //Note: bytes in textDecoder are ignored
          resolve(undefined);
      } else {
          var chunk = textDecoder.decode(result.value, {
              stream: true
          });
          onProgressCallback(chunk);
          readNextChunk();
      }
  })["catch"](function(error) {
      reject(error);
  });
};

shengzhou1216 avatar May 06 '23 03:05 shengzhou1216

same issue here. network error occurs in readNextChunk method.

var readNextChunk = function readNextChunk() {
  reader.read().then(function(result) {
      if (result.done) {
          //Note: bytes in textDecoder are ignored
          resolve(undefined);
      } else {
          var chunk = textDecoder.decode(result.value, {
              stream: true
          });
          onProgressCallback(chunk);
          readNextChunk();
      }
  })["catch"](function(error) {
      reject(error);
  });
};

I have found the problem after checking the server code. I configed a WriteTimeout option in server, it will auto close the connection after WriterTimeout. After unset this option, everything works fine. :smile:

shengzhou1216 avatar May 06 '23 09:05 shengzhou1216

@monstrum this error because http 1.x version cannot handle long live connections . So, you have 2 options

  1. Setup http2 handshake (mostly all browser's support) . But you may also need TLS instead of ssl . Http2 can handle long live connections.
  2. Simple, add heartbeatTimeout option to less time while initializing eventsource

Happy coding :)

pvtulsiram538 avatar Aug 29 '23 11:08 pvtulsiram538