-
Notifications
You must be signed in to change notification settings - Fork 910
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
Conversation
74a2f3b
to
8d123ee
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
} | ||
|
||
private void closeChannel(ChannelHandlerContext ctx) { | ||
assert ctx.executor().inEventLoop(); |
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.
Think we can avoid this by scheduling this within the event loop instead of the executor
ctx.channel().eventLoop()
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.
Fixed
/** | ||
* Whether idle connection should be removed after the {@link #CONNECTION_MAX_IDLE_TIMEOUT} has passed. | ||
*/ | ||
public static final SdkHttpConfigurationOption<Boolean> REAP_IDLE_CONNECTIONS = |
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.
minor, how about REAP_IDLE_CONNECTIONS_ENABLED
or ENABLE_REAP_IDLE_CONNECTIONS
?
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.
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 { |
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.
Can we add some unit tests for this class?
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.
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); |
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.
If the channel is closed on line 65, do we still do delegatePool.release(channel, promise)
?
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.
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 { |
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.
Can we add some unit tests for this class? Let's add a test class for every new class :)
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.
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.
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.
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! 🍻)
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.
Added tests for the release-on-close behavior.
5fbdc54
to
7135f60
Compare
@@ -0,0 +1,49 @@ | |||
package software.amazon.awssdk.http.nio.netty.internal; |
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.
Hmm, seems missing copyright headers on the test classes. (We need to add the checkstyles for test files)
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.
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
7135f60
to
32337e4
Compare
…a16bed24d Pull request: release <- staging/c640cb78-709b-4cf8-95b2-b8ea16bed24d
useIdleConnectionReaper
,connectionTimeToLive
andconnectionMaxIdleTime
to the Netty HTTP client.Fixes #856