Skip to content

Unhandled rejection when connection to eventsource gets terminated #224

@jayakrishnankp

Description

@jayakrishnankp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions