-
Notifications
You must be signed in to change notification settings - Fork 916
Fix ApacheHttpClient to use socket keep alive when appropriate #2373
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
f8f2e17
to
d01d32e
Compare
Thank you for the PR! We will take a look shortly |
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.
Could you add a changelog entry? You can generate one by running the scripts/new-change
script and following the instructions.
/** | ||
* Configure the connection to use java.net.SocketOptions.SO_KEEPALIVE. | ||
*/ | ||
Builder connectionKeepalive(Boolean keepConnectionAlive); |
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.
Same as above. Can we change it to tcpKeepAlive
?
@@ -675,10 +693,10 @@ public void checkServerTrusted(X509Certificate[] x509Certificates, String s) thr | |||
}; | |||
} | |||
|
|||
private SocketConfig buildSocketConfig(AttributeMap standardOptions) { | |||
private SocketConfig buildSocketConfig(AttributeMap standardOptions, | |||
Boolean soKeepAlive) { |
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 get soKeepAlive from standardOptions.get(SdkHttpConfigurationOption.TCP_KEEPALIVE)
directly instead of passing it?
/** | ||
* Whether or not to use keepalive on the connection. | ||
*/ | ||
public static final SdkHttpConfigurationOption<Boolean> CONNECTION_KEEPALIVE = |
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 rename it to TCP_KEEPALIVE
so that users don't confuse it with HTTP keep alive?
@@ -116,6 +122,7 @@ | |||
private static final Duration DEFAULT_CONNECTION_TIMEOUT = Duration.ofSeconds(2); | |||
private static final Duration DEFAULT_CONNECTION_ACQUIRE_TIMEOUT = Duration.ofSeconds(10); | |||
private static final Duration DEFAULT_CONNECTION_MAX_IDLE_TIMEOUT = Duration.ofSeconds(60); | |||
private static final Boolean DEFAULT_CONNECTION_KEEPALIVE = Boolean.TRUE; |
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.
We should probably make it default to false so that it has the same behavior as now.
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.
Sorry, thought it was, not sure what happened there.
a1ffc01
to
8aa2889
Compare
@zoewangg - thanks for the code review, it's much cleaner now. |
Codecov Report
@@ Coverage Diff @@
## master #2373 +/- ##
============================================
- Coverage 77.68% 77.66% -0.03%
Complexity 366 366
============================================
Files 1246 1245 -1
Lines 39358 39301 -57
Branches 3110 3106 -4
============================================
- Hits 30577 30522 -55
Misses 7291 7291
+ Partials 1490 1488 -2
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
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.
Thanks for updating the PR! Just have one minor comment, otherwise lgtm.
...clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/ApacheHttpClient.java
Outdated
Show resolved
Hide resolved
return this; | ||
} | ||
|
||
public void setTcpKeepalive(Boolean keepConnectionAlive) { |
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.
It seems the setter also needs to be updated to setTcpKeepAlive
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.
Missed that one, thank you.
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.
LGTM. Thank you for your contribution!
SonarCloud Quality Gate failed. |
@all-contributors please add @ajs139 for code |
I've put up a pull request to add @ajs139! 🎉 |
…bfe69efaa Pull request: release <- staging/1611ed87-a79f-4f4f-88a8-66ebfe69efaa
Description
This enables the underlying
Socket.SO_KEEPALIVE
when theCONNECTION_KEEPALIVE
configuration option is set totrue
.Motivation and Context
There's a known issue when using a NAT gateway that it times out after 350 seconds if the connection is not kept alive. If using ApacheHttpClient to create connections to an AWS Lambda from a machine within the VPC it appears that this connection goes through the NAT. This means that any Lambda invocations taking more than 350 seconds will never get a response.
Testing
Deployed the code to environment that was experiencing the timeout issue, and verified that setting
setSoKeepAlive(true)
on theSocketConfig
enabled keep-alive and allowed connections running longer than 350 seconds to respond.Screenshots (if appropriate)
Types of changes
Checklist
mvn install
succeedsLicense