aws-sdk-java: java.net.UnknownHostException: ec2.us-east-1.amazonaws.com
Recently encountered an issue that seems related to this particular GitHub issue. (#813)
Circumstance is a redundant network (2N+1) in the midst of a true partition event. Access to EC2 was lost to some users within organization. (around 2018-03-02; see relevant AWS status incidents). After partition event was resolved user connectivity issues to EC2 resolved, but our existing Scala process (running the java-sdk) was unable to recover - this went on for at least 5 hours. However stopping the process and starting it again immediately restored the connectivity.
The relevant part of the stack traces:
Caused by: java.net.UnknownHostException: ec2.us-east-1.amazonaws.com
at java.net.InetAddress.getAllByName0(InetAddress.java:1280) ~[na:1.8.0_131]
at java.net.InetAddress.getAllByName(InetAddress.java:1192) ~[na:1.8.0_131]
at java.net.InetAddress.getAllByName(InetAddress.java:1126) ~[na:1.8.0_131]
at com.amazonaws.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:27) ~[com.amazonaws.aws-java-sdk-core-1.11.129.jar:na]
at com.amazonaws.http.DelegatingDnsResolver.resolve(DelegatingDnsResolver.java:38) ~[com.amazonaws.aws-java-sdk-core-1.11.129.jar:na]
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:111) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_131]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_131]
at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:76) ~[com.amazonaws.aws-java-sdk-core-1.11.129.jar:na]
at com.amazonaws.http.conn.$Proxy25.connect(Unknown Source) ~[na:na]
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55) ~[org.apache.httpcomponents.httpclient-4.5.2.jar:4.5.2]
at com.amazonaws.http.apache.client.impl.SdkHttpClient.execute(SdkHttpClient.java:72) ~[com.amazonaws.aws-java-sdk-core-1.11.129.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1190) ~[com.amazonaws.aws-java-sdk-core-1.11.129.jar:na]
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1030) ~[com.amazonaws.aws-java-sdk-core-1.11.129.jar:na]
... 47 common frames omitted
2018-03-03 20:46:52,328 level=ERROR *OBFUSCATED*
com.amazonaws.SdkClientException: Unable to execute HTTP request: ec2.us-east-1.amazonaws.com
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 16 (6 by maintainers)
(solved) It only fails for SES, interestingly. The Java process I’m running also accesses S3, RDS (aurora), DynamoDB, and SNS. Those all work.
I created a pcap file with tcpdump out of curiosity, and noticed something screwy with the internal AWS DNS for SES vs other services.
That led me to dig into the code for the process, which turns out to be creating a VPN connection out of AWS to a client data center, reading some data, then closing the VPN.
Further, the code is initializing clients for S3, SNS, and DynamoDB BEFORE initiating the VPN.
The SES call was the first thing done AFTER closing the VPN. That made me suspicious, since the VPN connection is handled outside Java by an OS package.
I modified the code to add a delay before initializing the SNS client, and suddenly it worked!
So in my case, the generic stack trace was truly because the name was not resolvable when the code ran, starting today. It looks like a timing issue. I see a huge quantity of system packages updated last night, so something in there changed the timing of the network interface realignment after the VPN process exits. I think my solutions going forward are to keep a delay after closing, or initialize the SES client early, with the other service clients. That may be the safest course for future-proofing.
Since automatic package updates are part of our security model, we realize there will be some periodic hiccups like this, so I guess this isn’t an SDK issue from my perspective, unless there is more documentation that could be helpful somewhere. Probably this thread is the most helpful if others see this stack, since there are any number of reasons DNS lookups could fail.
Thank you for your questions, they got me thinking in the right direction.
I wanted to add my two cents, since I faced a similar issue in ECS:
In my case, I was running out of file descriptors (due to a bug), which made the DNS resolution fail. The hint was an additional “System Error” right before the UnknownHostExceptions started.