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

http2: confusion with how aborted ClientHttp2Stream is reported #56627

Open
santigimeno opened this issue Jan 16, 2025 · 1 comment
Open

http2: confusion with how aborted ClientHttp2Stream is reported #56627

santigimeno opened this issue Jan 16, 2025 · 1 comment
Labels
http2 Issues or PRs related to the http2 subsystem.

Comments

@santigimeno
Copy link
Member

Take this sample code:

const h2 = require('http2');

const server = h2.createServer();
server.on('stream', (stream) => {
  stream.session.destroy();
});

server.listen(0, () => {
  const client = h2.connect(`http://localhost:${server.address().port}`);

  client.on('close', () => {
    server.close();;
  });

  const clientStream = client.request();
  clientStream.on('aborted', () => {
    // Never called
    console.log('aborted');
  });

  clientStream.on('close', () => {
    // `rstCode === 8 (NGHTTP2_CANCEL) 
    console.log('close', clientStream.rstCode);
  });
  
  clientStream.on('error', (err) => {
    // Never called
    throw err;
  });
});

in which clientStream is aborted before any response is generated via the stream.session.destroy() call. I would expect in this case clientStream to emit an error, but by looking at the code, this specific case is explicitly not reporting the error because:

// RST code 8 not emitted as an error as its used by clients to signify
// abort and is already covered by aborted event, also allows more
// seamless compatibility with http1

but, as demonstrated in the example, the aborted event is not reported. I don't know exactly what the http1 compatibility means in this context.

Also, if we look at the documentation of the Http2Stream close event, it seems to contradict the following statement:

The HTTP/2 error code used when closing the stream can be retrieved using the http2stream.rstCode property. If the code is any value other than NGHTTP2_NO_ERROR (0), an 'error' event will have also been emitted.

Any thoughts whether this is a bug in the code, the documentation, both?.

Thanks!

@santigimeno santigimeno added the http2 Issues or PRs related to the http2 subsystem. label Jan 16, 2025
@RafaelGSS
Copy link
Member

cc: @nodejs/http2

IMO, this seems to be a bug in the code, but it might be a workaround instead due to the number of tests that break if we revert that operation. I'd defer the suggestion to @mcollina @jasnell @addaleax, but in case of no response, I'd try to emit a stream error in that scenario.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http2 Issues or PRs related to the http2 subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants