Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,13 @@ public HttpConnectionPoolManager(HttpConnectionSettings settings)
// However, we can only do such optimizations if we're not also tracking
// connections per server, as we use data in the associated data structures
// to do that tracking.
// Additionally, we should not avoid storing connections if keep-alive ping is configured,
// as the heartbeat timer is needed for ping functionality.
bool avoidStoringConnections =
settings._maxConnectionsPerServer == int.MaxValue &&
(settings._pooledConnectionIdleTimeout == TimeSpan.Zero ||
settings._pooledConnectionLifetime == TimeSpan.Zero);
settings._pooledConnectionLifetime == TimeSpan.Zero) &&
settings._keepAlivePingDelay == Timeout.InfiniteTimeSpan;

// Start out with the timer not running, since we have no pools.
// When it does run, run it with a frequency based on the idle timeout.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ await Http2LoopbackServer.CreateClientAndServerAsync(async uri =>

[OuterLoop("Runs long")]
[Theory]
[InlineData(HttpKeepAlivePingPolicy.Always)]
[InlineData(HttpKeepAlivePingPolicy.WithActiveRequests)]
public async Task KeepAliveConfigured_KeepAlivePingsAreSentAccordingToPolicy(HttpKeepAlivePingPolicy policy)
[InlineData(HttpKeepAlivePingPolicy.Always, -1)]
[InlineData(HttpKeepAlivePingPolicy.WithActiveRequests, -1)]
[InlineData(HttpKeepAlivePingPolicy.WithActiveRequests, 0)]
public async Task KeepAliveConfigured_KeepAlivePingsAreSentAccordingToPolicy(HttpKeepAlivePingPolicy policy, int connectionLifetimeMilliseconds)
{
await Http2LoopbackServer.CreateClientAndServerAsync(async uri =>
{
SocketsHttpHandler handler = CreateSocketsHttpHandler(allowAllCertificates: true);
handler.KeepAlivePingTimeout = TimeSpan.FromSeconds(10);
handler.KeepAlivePingPolicy = policy;
handler.KeepAlivePingDelay = TimeSpan.FromSeconds(1);
handler.PooledConnectionLifetime = TimeSpan.FromMilliseconds(connectionLifetimeMilliseconds);

using HttpClient client = new HttpClient(handler);
client.DefaultRequestVersion = HttpVersion.Version20;
Expand Down
Loading