Skip to content

uncaughtException in unidici.request() #5525

Closed

Description

@jeroen

My app uses unidici 8.7.0 to download files from CloudFlare R2:

const fast_dispatcher = new Agent().compose(interceptors.redirect({maxRedirections: 5}));
function get_download_stream_fast(url){
  return request(url, {
    dispatcher: fast_dispatcher,
    signal: AbortSignal.timeout(30000)
  }).then(function({statusCode, body}){
    if(statusCode >= 200 && statusCode < 300){
      return body;
    }
    body.dump(); //free the connection, we don't use the body
    throw new Error(`HTTP ${statusCode} for: ${url}`);
  });
}

My app also monitors for uncaughtException errors:

process.on('uncaughtException', function(err) {
  console.log( "[UNCAUGHT EXCEPTION] " + err.stack || err.message );
  process.exit(1);
});

I am regularly seeing these in my logs (which seems to correlate with downloads hitting the 30s timeout above).

 [UNCAUGHT EXCEPTION] SocketError: other side closed
     at TLSSocket.onHttp2SocketEnd (/frontend/node_modules/undici/lib/dispatcher/client-h2.js:661:22)
     at TLSSocket.emit (node:events:531:35)
     at endReadableNT (node:internal/streams/readable:1698:12)
     at process.processTicksAndRejections (node:internal/process/task_queues:89:21)

Perhaps the CDN is not always 100% reliable. Is there a way to catch these exceptions, or should I just ignore them?

Activity

  1. jeroen commented on Jul 27, 2026

    @jeroen
    Author

    After updating to 8.8.0 now seeing these errors:

    UNCAUGHT EXCEPTION] SocketError: other side closed
      at TLSSocket.onHttp2SocketEnd (/frontend/node_modules/undici/lib/dispatcher/client-h2.js:645:22)
      at TLSSocket.emit (node:events:531:35)
      at endReadableNT (node:internal/streams/readable:1698:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:89:21)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions