Skip to content

http2: Fix issue where slow requests are terminated prematurely#879

Closed
hyperair wants to merge 4 commits intogoogleapis:mainfrom
hyperair:fix-http2-premature-session-destroy
Closed

http2: Fix issue where slow requests are terminated prematurely#879
hyperair wants to merge 4 commits intogoogleapis:mainfrom
hyperair:fix-http2-premature-session-destroy

Conversation

@hyperair
Copy link

@hyperair hyperair commented Jan 6, 2026

This PR fixes an issue where http2 requests taking longer than 500ms will be terminated prematurely, with http2.request silently resolving with truncated responses instead of rejecting with an error.

The issue comes from starting the idle shutdown timer (500ms) immediately after the beginning of the latest request on the session, and not detecting that the session is still actively transferring data before forcefully terminating the session.

This PR fixes that by switching the connection idle shutdown timer to session.setTimeout instead of setTimeout.

I've also verified that this fix makes the client in https://github.com/hyperair/google-http2-bug-demo work correctly (more info here):

  • all requests return the correct untruncated data
  • client process shuts down properly after all requests are done

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #768 🦕

Use `session.setTimeout` instead of `setTimeout` for the idle shutdown timer.

Fixes: googleapis#768
FakeClient now needs a setTimeout function
@hyperair hyperair requested a review from a team as a code owner January 6, 2026 10:41
@google-cla
Copy link

google-cla bot commented Jan 6, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@sofisl sofisl requested a review from a team as a code owner March 12, 2026 20:31
@sofisl
Copy link
Contributor

sofisl commented Mar 12, 2026

/gcbrun

Copy link
Contributor

@sofisl sofisl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, could we add a test to specifically make sure test errors are not swallowed prematurely (per your issue description)? TY!

@sofisl sofisl self-requested a review March 12, 2026 23:39
@sofisl
Copy link
Contributor

sofisl commented Mar 12, 2026

So sorry, I'm going to close this for now since we are in the middle of migrating this repo to google-cloud-node. would you mind reopening this PR on that repo when the migration is finished (probably next week) and just add a test as described above? TYSM!

@sofisl sofisl closed this Mar 12, 2026
@hyperair
Copy link
Author

Sure, could you drop me a ping on this issue when the migration's done please?

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.

HTTP/2 session is closed while file beeing uploaded

2 participants