Skip to content

uncaughtException : Stream closed with error code NGHTTP2_INTERNAL_ERROR #5586

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 sometimes seeing these in my logs:

[UNCAUGHT EXCEPTION] Error [ERR_HTTP2_STREAM_ERROR]: Stream closed with error code NGHTTP2_INTERNAL_ERROR
     at ClientHttp2Stream._destroy (node:internal/http2/core:2462:13)
     at _destroy (node:internal/streams/destroy:122:10)
     at ClientHttp2Stream.destroy (node:internal/streams/destroy:84:5)
     at Writable.destroy (node:internal/streams/writable:1122:11)
     at Http2Stream.onStreamClose (node:internal/http2/core:604:12)
     

The crash is the same teardown-race family as the UND_ERR_SOCKET errors from #5525: the remote peer resets a stream with INTERNAL_ERROR, Node's http2 core destroys the ClientHttp2Stream with an error, and at that moment undici no longer has an 'error' listener attached, so it escapes to uncaughtException.

It could be same as #2675 ?

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