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

Improve HTTP2/PING timeout logic #5018

Merged
merged 1 commit into from
Mar 22, 2024

Conversation

akidambisrinivasan
Copy link
Contributor

@akidambisrinivasan akidambisrinivasan commented Mar 15, 2024

Improve PING timeout logic to avoid premature closing of the connection that can occur due to delays in scheduling of writing PING frame to the channel and/or flushing it to the socket.

Motivation and Context

Current PING timeout logic doesnt work well when there are delays in scheduling or flushing to socket.

Scenario we want to avoid is shown below (NOTE: ptm - pingTimeoutMillis, Wx - Write Ping x, Fx - Flush Ping x, Rx - Receive ack x, T -Timeout)

When timer is scheduled periodically, even though ack2 comes < ptm after being flushed to the socket, we
will still timeout at 2ptm.        
 0          1ptm       2ptm       3ptm
|----------|----------|----------|-------> time
W1F1 R1    W2      F2 T  R2
When timer is scheduled after flushing, we allow time for ack to come back and not prematurely timeout.
0            ptm1               ptm2
|-|----------|------|----------|-----------> time
 W1F1 R1      W2     F2   R2    W3

The change prevents premature closing of the HTTP2 connection. With this change, it will detect dead connections which are otherwise not detected due to inactivity while tolerating scheduling and flushing delays.

Modifications

The callback to send the next ping is scheduled when the ping write is flushed, so it accounts for delays in flushing (because that delay doesnt mean the connection is dead)

Testing

Added 2 new unit tests:

  1. Add unit test to ensure that when there is a delay in writing to socket, if the ACK doesnt come within pingTimeoutMillis, the code still executes timeout logic and terminates the connection, but if it does come, resets the timer and continues pinging.
  2. If there is a scheduling delay, it does not execute timeout. For scheduling delay, the system of jvm is unable to catchup and will do so slowly, the true issue that needs to be fixed is by addressing the slowness not timing out the connection.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

Improve PING timeout logic to avoid premature closing of the connection that
can occur due to delays in scheduling of writing PING frame to the channel
and/or flushing it to the socket.
Copy link

@dagnir dagnir merged commit 161e0f7 into aws:master Mar 22, 2024
12 checks passed
@dagnir
Copy link
Contributor

dagnir commented Mar 22, 2024

@all-contributors please add @akidambisrinivasan for code

Copy link
Contributor

@dagnir

I've put up a pull request to add @akidambisrinivasan! 🎉

akidambisrinivasan added a commit to akidambisrinivasan/aws-sdk-java-v2 that referenced this pull request Jun 28, 2024
Improve PING timeout logic to avoid premature closing of the connection that
can occur due to delays in scheduling of writing PING frame to the channel
and/or flushing it to the socket.
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