-
Notifications
You must be signed in to change notification settings - Fork 851
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
java.net.ConnectException: Cannot assign requested address (connect failed) #2170
Comments
Can using UrlConnectionHttpClient instead of Apache http client cause this issue? |
Perhaps. According to the documentation, UrlConnectionHttpClient builder only takes connection timeout and socket timeout, the other configurations are ignored. Have you tested with ApacheHttpClient? Are you creating one new DynamoDB client per request or are you sharing the client instance? We recommend to share the instance if possible - for more best practices: https://github.com/aws/aws-sdk-java-v2/blob/master/docs/BestPractices.md |
Tested with ApacheHttpClient and it has solved our issue. We don't create DDB client for every request and reuse across all requests. Regarding urlconnection client ignoring those configuration, I wanted to highlight code of Urlconnection client method - https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/url-connection-client/src/main/java/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClient.java#L343 ApacheHttp client method - https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/ApacheHttpClient.java#L583 If we look at error again - Reading further on internet regarding implementation of java HttpURLConnection client, it looks like HttpURLConnection may not be supporting HTTP persistence connection feature and it tries to open new socket for every request. Or may be aws sdk's UrlConnectionHttpClient class is trying to create new socket for every request which is causing this error. I am not fully sure but this might be the root-cause here. May be SDK team can further confirm here if they have more idea around UrlConnectionHttpClient implementation. It would be great to confirm the root-cause here and also if there is a way to solve this issue with UrlConnectionHttpClient |
Hi @mihirshah91, apologies for the delayed response.
Here is an example of how to configure them: Lines 240 to 249 in 8728dbb
The Java SDK's Per HttpURLConnection doc https://docs.oracle.com/javase/7/docs/technotes/guides/net/http-keepalive.html, it should by default reuse connections. This can be configured by The maximum number of connections per destination to be kept alive is default to 5. You can configure it via Could you try tuning those configurations to see if it helps? |
It looks like this issue hasn’t been active in longer than a week. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please add a comment to prevent automatic closure, or if the issue is already closed please feel free to reopen it. |
Hi @zoewangg thanks for the info. How can we configure |
You can configure it using |
ok, thanks. I am closing this issue. As a resolution we had moved to apache client. But will keep this in mind if we want to switch back |
|
I am connecting to DDB using sts assume role policy for cross-account access
During our load-test, I am seeing
java.net.ConnectException: Cannot assign requested address (connect failed)
when executing read query on DDB table. Under normal load, it works fine. Problem happens when load testing the service. Pasted full stack trace in current behaviour sectionI am setting required timeouts on DDB client and also have increased max connections to support load test still seeing this error. Following is DDB client and sts client configs
STS and DDB client settings:
Expected Behavior
Mentioned exception should not be thrown under high load
Current Behavior
Full stack trace:
Possible Solution
Any pointers on how to avoid Cannot assign requested address (connect failed)? Does it mean that there is no available tcp port for opening socket? If yes, how can I fix it?
Steps to Reproduce (for bugs)
N/A
Context
It affects using sdk java v2 client for our new feature since it doesn't work as expected under high load
Your Environment
The text was updated successfully, but these errors were encountered: