Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled rejection when connection to eventsource gets terminated #224

Open
jayakrishnankp opened this issue Nov 16, 2023 · 5 comments
Open

Comments

@jayakrishnankp
Copy link

I am using the event-source-polyfill library to create an EventSource connection in my Nodejs project using the dynamic imports mentioned in docs.

The connection to the eventsource server gets terminated occasionally due to unknown reasons.

Expected behaviour:

Eventsource catches the error caused by connection termination and handles it as required

Actual behaviour:

The error thrown due to this termination is not caught, leading to an unhandlerejection in the node process. The error stack I obtain is:

TypeError: terminated
    at Fetch.onAborted (node:internal/deps/undici/undici:14036:53)
    at Fetch.emit (node:events:513:28)
    at Fetch.emit (node:domain:489:12)
    at Fetch.terminate (node:internal/deps/undici/undici:13295:14)
    at Object.onError (node:internal/deps/undici/undici:14131:36)
    at Request.onError (node:internal/deps/undici/undici:7601:31)
    at errorRequest (node:internal/deps/undici/undici:9797:17)
    at TLSSocket.onSocketClose (node:internal/deps/undici/undici:9248:9)
    at TLSSocket.emit (node:events:525:35)
    at TLSSocket.emit (node:domain:489:12) {
  [cause]: BodyTimeoutError: Body Timeout Error
      at Timeout.onParserTimeout [as _onTimeout] (node:internal/deps/undici/undici:9189:32)
      at listOnTimeout (node:internal/timers:571:11)
      at process.processTimers (node:internal/timers:512:7) {
    code: 'UND_ERR_BODY_TIMEOUT'
  }
}

Additional details

The EventSource is initialized by:

import('@titelmedia/node-fetch').then(function (fetch) {
      globalThis.fetch = fetch.default;
      globalThis.Response = fetch.default.Response;
      const source = new EventSource(url);
      callback(null, source);
    });

The error is thrown from time-to-time when the eventsource times out and creates a new connection.

@RayHughes
Copy link

RayHughes commented Nov 28, 2023

We are experiencing a similar issue when using this library with React Native.

Simulator Screenshot - iPhone 15 Pro Max - 2023-11-27 at 20 20 48
Simulator Screenshot - iPhone 15 Pro Max - 2023-11-27 at 20 26 35

@Gijela
Copy link

Gijela commented Apr 15, 2024

Is there an answer to that question now?

@jayakrishnankp
Copy link
Author

Bump

@Yaffle
Copy link
Owner

Yaffle commented Jun 27, 2024

You are saying it is "connection termination", but really the line of code of XMLHttpRequest.js looks like something else. Is it a bug of that lib? The attached stack trace does look relevant to EventSorce library. Is the exception really not caught?

@jayakrishnankp
Copy link
Author

jayakrishnankp commented Jul 3, 2024

You are saying it is "connection termination"

I am not sure what is happening in my case but even with a proper internet connection, the request throws this exception with the error message of "TypeError: terminated" with the cause always as UND_ERR_BODY_TIMEOUT. And it happens every 3-5 minutes.

If there is anything I can do to get clearer error messages or more info, please do suggest them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants