Yaffle / EventSource

a polyfill for http://www.w3.org/TR/eventsource/
MIT License
2.11k stars 338 forks source link

Type Error: network error #195

Open monstrum opened 2 years ago

monstrum commented 2 years ago

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

botjaeger commented 2 years ago

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

leik-software commented 2 years ago

Same here...any workarounds?

felicandalc commented 2 years ago

Nothing yet?

shengzhou1216 commented 1 year ago

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 commented 1 year ago

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:

pvtulsiram538 commented 1 year ago

@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 heartbeatTimeoutoption to less time while initializing eventsource

Happy coding :)