-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Configure ping in HTTP2 #40257
Configure ping in HTTP2 #40257
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
src/libraries/System.Net.Http.WinHttpHandler/ref/System.Net.Http.WinHttpHandler.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two major questions:
- Is the timer with
HeartBeat
right approach? - Is it worth the extra class
Http2KeepAlive
?
@scalablecory you're opinions?
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass review done; will provide a 2nd pass once comments are resolved.
src/libraries/System.Net.Http/src/System/Net/Http/HttpHandlerDefaults.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/HttpHandlerDefaults.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
...ibraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPool.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/tests/FunctionalTests/SocketsHttpHandlerTest.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Show resolved
Hide resolved
Just thinking, but instead of the However, I don't know if this would be worse or better on the resources than the shared timer across all connections. |
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs
Outdated
Show resolved
Hide resolved
{ | ||
thisRef.HeartBeat(); | ||
} | ||
}, new WeakReference<HttpConnectionPoolManager>(this), TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All implementations I have seen of pinging says that unreasonably low values for ping delay and timeout are not allowed.
1 second for the heartbeat is fine - this is what we do in Kestrel - but I think the KeepAlivePingDelay and KeepAlivePingTimeout should disallow values smaller than a second. That way developers won't expect to be able to configure KeepAlivePingDelay = TimeSpan.FromMillisecond(1)
and expect a ping to be sent every millisecond.
...ibraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpConnectionPoolManager.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2KeepAlive.cs
Outdated
Show resolved
Hide resolved
One problem is time would slowly drift. Each iteration would be PingDelay + time to execute heartbeat logic. You'd need to calculate that time and subtract it from PingDelay when doing the next delay. Even with that time would probably slowly drift. I haven't looked at the Timer source but it will no doubt have optimizations that make it a better choice than Task.Delay calls in a loop. |
Using |
Cool, it was just a suggestion. And I learned something new. Keep the heartbeat. |
/azp run runtime-libraries outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
On slower platforms, PINGs were coming sooner than requests themselves causing errors while reading the request and receiving PING frame instead of HEADERS frame.
/azp run runtime-libraries outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-libraries outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-libraries outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run runtime-libraries outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/SocketsHttpHandler.cs
Outdated
Show resolved
Hide resolved
@ManickaP FYI The |
Is there a bug tracking the failure? |
It's bug in test, no need for tracking issue, I'm working on it right know. |
@ManickaP, thanks for finish this PR! |
Allows configure HTTP2 ping on SocketsHttpHandler:
The
KeepAlivePingDelay
defines how often the ping is sent. Any incoming frame can postpone the ping request. It means during vivacious communication the ping will not be sent at all as the communication itself manifest the connection is live. The time resolution is 1s.KeepAlivePingTimeout
defines the ping ack timeout. The time resolution is 1s.KeepAlivePingPolicy
defines in what circumstances the ping is sent:WithActiveRequests
- only if the connection has an active streamAlways
- send the ping always - even if the connection is returned to the connection pool and no streams are active.When the ping detects the connection is active, it closes the connection.
What to expect
What to not expect
fixes #31198