Skip to content

Updated connection lifecycle behavior. #1055

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

Merged
merged 2 commits into from
Feb 4, 2019

Conversation

millems
Copy link
Contributor

@millems millems commented Feb 1, 2019

  1. Added support for useIdleConnectionReaper, connectionTimeToLive and connectionMaxIdleTime to the Netty HTTP client.
  2. Enable the idle connection reaper by default for apache and netty clients. Connection time-to-live remains disabled by default.

Fixes #856

@millems millems force-pushed the millem/netty-idle-connection-reaper branch from 74a2f3b to 8d123ee Compare February 1, 2019 21:49
@codecov-io
Copy link

codecov-io commented Feb 1, 2019

Codecov Report

Merging #1055 into master will increase coverage by 0.05%.
The diff coverage is 75.2%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1055      +/-   ##
============================================
+ Coverage     55.96%   56.02%   +0.05%     
- Complexity     4614     4648      +34     
============================================
  Files           815      818       +3     
  Lines         27824    27915      +91     
  Branches       2247     2253       +6     
============================================
+ Hits          15572    15639      +67     
- Misses        11532    11549      +17     
- Partials        720      727       +7
Impacted Files Coverage Δ Complexity Δ
...sdk/http/apache/internal/DefaultConfiguration.java 100% <ø> (ø) 1 <0> (ø) ⬇️
...amazon/awssdk/http/SdkHttpConfigurationOption.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...nio/netty/internal/ChannelPipelineInitializer.java 44.44% <100%> (+5.66%) 6 <1> (+2) ⬆️
...dk/http/nio/netty/internal/NettyConfiguration.java 92.85% <100%> (+1.94%) 11 <3> (+3) ⬆️
...k/http/nio/netty/internal/ChannelAttributeKey.java 91.66% <100%> (+0.75%) 2 <0> (ø) ⬇️
...re/amazon/awssdk/http/apache/ApacheHttpClient.java 61.49% <50%> (-0.94%) 17 <1> (-1)
...o/netty/internal/http2/HttpOrHttp2ChannelPool.java 65.67% <62.5%> (-1%) 15 <2> (ø)
...io/netty/internal/IdleConnectionReaperHandler.java 72.72% <72.72%> (ø) 4 <4> (?)
...awssdk/http/nio/netty/NettyNioAsyncHttpClient.java 66.92% <73.91%> (+0.55%) 18 <1> (+1) ⬆️
...nio/netty/internal/OldConnectionReaperHandler.java 90.9% <90.9%> (ø) 15 <15> (?)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 16b0c9c...32562c8. Read the comment docs.

}

private void closeChannel(ChannelHandlerContext ctx) {
assert ctx.executor().inEventLoop();
Copy link
Contributor

Choose a reason for hiding this comment

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

Think we can avoid this by scheduling this within the event loop instead of the executor

ctx.channel().eventLoop()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

/**
* Whether idle connection should be removed after the {@link #CONNECTION_MAX_IDLE_TIMEOUT} has passed.
*/
public static final SdkHttpConfigurationOption<Boolean> REAP_IDLE_CONNECTIONS =
Copy link
Contributor

Choose a reason for hiding this comment

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

minor, how about REAP_IDLE_CONNECTIONS_ENABLED or ENABLE_REAP_IDLE_CONNECTIONS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following the naming convention of TRUST_ALL_CERTIFICATES, which we can't change now. I'd rather be consistent.

* A handler that closes unused channels that have not had any traffic on them for a configurable amount of time.
*/
@SdkInternalApi
public class IdleConnectionReaperHandler extends IdleStateHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some unit tests for this class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its behavior is tested at build time with the functional tests.

In my opinion, that is better and sufficient for this class. Direct unit tests would be too coupled to the actual class implementation, and would make it impossible to evolve the class over time without having to go back and update the unit tests.

channel.close();
}

delegatePool.release(channel, promise);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the channel is closed on line 65, do we still do delegatePool.release(channel, promise)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ChannelPool#acquire() documents: <strong>Its important that an acquired is always released to the pool again, even if the {@link Channel} is explicitly closed..</strong>

* before it is released to the underlying pool.
*/
@SdkInternalApi
public class HonorCloseOnReleaseChannelPool implements ChannelPool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add some unit tests for this class? Let's add a test class for every new class :)

Copy link
Contributor Author

@millems millems Feb 2, 2019

Choose a reason for hiding this comment

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

I disagree. Too many class-level tests for simple classes with a large number of dependencies (like this one) makes the code base too rigid and hard to update. Class-level tests written for this class: (a) wouldn't verify it actually works, just that it calls the methods we think we should, and (b) would almost certainly have to be updated if we ever touch the implementation.

This class's behavior is better tested (imo) with the functional tests, run at build time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed in person. We agree that unit test class for IdleConnectionReaperHandler.java is not needed since the functional tests would cover it. However, the functional test might not cover this class, so unit tests for this class are needed. (Fun fight! 🍻)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added tests for the release-on-close behavior.

@millems millems force-pushed the millem/netty-idle-connection-reaper branch 3 times, most recently from 5fbdc54 to 7135f60 Compare February 4, 2019 19:44
@@ -0,0 +1,49 @@
package software.amazon.awssdk.http.nio.netty.internal;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, seems missing copyright headers on the test classes. (We need to add the checkstyles for test files)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

1. Added support for `useIdleConnectionReaper`, `connectionTimeToLive` and `connectionMaxIdleTime` to the Netty HTTP client.
2. Enable the idle connection reaper by default for apache and netty clients. Connection time-to-live remains disabled by default.

Fixes #856
@millems millems force-pushed the millem/netty-idle-connection-reaper branch from 7135f60 to 32337e4 Compare February 4, 2019 20:01
@millems millems merged commit 71ca4c1 into master Feb 4, 2019
@millems millems deleted the millem/netty-idle-connection-reaper branch March 17, 2020 23:39
aws-sdk-java-automation added a commit that referenced this pull request Nov 24, 2020
…a16bed24d

Pull request: release <- staging/c640cb78-709b-4cf8-95b2-b8ea16bed24d
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.

4 participants