Skip to content

Conversation

@mcollina
Copy link
Member

Summary

  • Fixes flaky Dispatcher#Connect test on macOS in test/http2-dispatcher.js
  • The 'end' event handler was incorrectly treating stream state 6 (HALF_CLOSED_REMOTE) as an error
  • State 6 is actually the expected state when the peer sends END_STREAM

Problem

The test was failing intermittently on macOS with:

Error [InformationalError]: HTTP/2: stream half-closed (remote)

The root cause was a stream state check stream.state.state < 6 that excluded state 6, but this is the normal state when the remote side finishes sending data. Timing differences across platforms caused this to appear as a flaky test.

Fix

Simplified the 'end' event handler by:

  • Removing the unnecessary stream state check (the 'end' event only fires when readable side is complete)
  • Removing the duplicate kOpenStreams decrement (the 'close' handler already handles this)

Test plan

  • test/http2-dispatcher.js passes (including Dispatcher#Connect)
  • H2 abort, goaway, trailers tests pass

The 'end' event handler in client-h2.js was incorrectly treating stream
state 6 (HALF_CLOSED_REMOTE) as an error condition. This state is the
expected state when the peer sends END_STREAM, per the HTTP/2 spec.

The timing of when the stream reaches this state varies across platforms,
causing the Dispatcher#Connect test in test/http2-dispatcher.js to fail
intermittently on macOS with "HTTP/2: stream half-closed (remote)" error.

This commit simplifies the 'end' event handler by:
- Removing the unnecessary stream state check
- Removing the duplicate kOpenStreams decrement (already handled in 'close')
- Always completing the request normally when 'end' fires

The stream cleanup is properly handled by the 'close' event handler,
which decrements kOpenStreams and manages session references.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
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

Successfully merging this pull request may close these issues.

2 participants