Skip to content

Commit

Permalink
Check for timeToLive == 0
Browse files Browse the repository at this point in the history
Allows setting connection timeToLive and validateAfterInactivity to zero to always close or validate a connection
  • Loading branch information
ChristophKaser authored and ok2c committed Jul 22, 2023
1 parent d72a136 commit 2236696
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,17 @@ public synchronized ConnectionEndpoint get(
if (poolEntry.hasConnection()) {
final TimeValue timeToLive = connectionConfig.getTimeToLive();
if (TimeValue.isNonNegative(timeToLive)) {
final Deadline deadline = Deadline.calculate(poolEntry.getCreated(), timeToLive);
if (deadline.isExpired()) {
if (timeToLive.getDuration() == 0
|| Deadline.calculate(poolEntry.getCreated(), timeToLive).isExpired()) {
poolEntry.discardConnection(CloseMode.GRACEFUL);
}
}
}
if (poolEntry.hasConnection()) {
final TimeValue timeValue = resolveValidateAfterInactivity(connectionConfig);
if (TimeValue.isNonNegative(timeValue)) {
final Deadline deadline = Deadline.calculate(poolEntry.getUpdated(), timeValue);
if (deadline.isExpired()) {
if (timeValue.getDuration() == 0
|| Deadline.calculate(poolEntry.getUpdated(), timeValue).isExpired()) {
final ManagedHttpClientConnection conn = poolEntry.getConnection();
boolean stale;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ public void completed(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> p
if (poolEntry.hasConnection()) {
final TimeValue timeToLive = connectionConfig.getTimeToLive();
if (TimeValue.isNonNegative(timeToLive)) {
final Deadline deadline = Deadline.calculate(poolEntry.getCreated(), timeToLive);
if (deadline.isExpired()) {
if (timeToLive.getDuration() == 0
|| Deadline.calculate(poolEntry.getCreated(), timeToLive).isExpired()) {
poolEntry.discardConnection(CloseMode.GRACEFUL);
}
}
Expand All @@ -288,8 +288,8 @@ public void completed(final PoolEntry<HttpRoute, ManagedAsyncClientConnection> p
final ManagedAsyncClientConnection connection = poolEntry.getConnection();
final TimeValue timeValue = connectionConfig.getValidateAfterInactivity();
if (connection.isOpen() && TimeValue.isNonNegative(timeValue)) {
final Deadline deadline = Deadline.calculate(poolEntry.getUpdated(), timeValue);
if (deadline.isExpired()) {
if (timeValue.getDuration() == 0
|| Deadline.calculate(poolEntry.getUpdated(), timeValue).isExpired()) {
final ProtocolVersion protocolVersion = connection.getProtocolVersion();
if (protocolVersion != null && protocolVersion.greaterEquals(HttpVersion.HTTP_2_0)) {
connection.submitCommand(new PingCommand(new BasicPingHandler(result -> {
Expand Down

0 comments on commit 2236696

Please sign in to comment.