question

bgglenn avatar image
bgglenn asked

Host becomes unreachable

My app makes periodic updates to a server from a service. This works fine for a long time, but then connections to the server begin failing with EHOSTUNREACH (no route to host). Once this happens, all communication with that IP fails, even in the browser or pinging from a shell. Connections to any other host continue to work fine, and other systems on the same network can access the server. "ip route show" doesn't show anything unusual. This has happened twice, and it doesn't recover automatically; last time I had to reboot. This is on a wifi Fire HD 7". I'll give logcat output on request (don't see an attach file option), but first, is this a known issue?
fire tablet
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Bgglenn, Thank you for your post. Can you please post sample code of how you are making HTTP calls to your server?
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bgglenn avatar image
bgglenn answered
It's just a simple HTTP POST using java.net.HttpURLConnection in an AsyncTask. I don't know that showing it will help, since the host is unreachable from the whole system, even in the browser, but here you go (don't know if this will be readable--the "preview" button on this forum is broken and I don't know how to markup a code block): class RequestTask extends AsyncTask { @Override protected LowLevelResult doInBackground(RequestTaskData... requestStrings) { RequestTaskData request = requestStrings[0]; JSONObject requestJSON = request.requestJSON; URL url; try { url = new URL(request.url); } catch (MalformedURLException e) { throw new RuntimeException(e); } LowLevelResult result = new LowLevelResult(); try { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Accept-Charset", "UTF-8"); connection.setRequestProperty("Content-Type", "application/json"); // Write the request. OutputStream output = connection.getOutputStream(); output.write(requestJSON.toString().getBytes("UTF-8")); output.close(); // Read the result. InputStream response = connection.getInputStream(); result.resultString = readUTF8FromStream(response); response.close(); result.resultResponseCode = connection.getResponseCode(); return result; } catch (IOException e) { result.resultException = e; return result; } } static public ByteArrayOutputStream readDataFromStream(InputStream file) throws IOException { ByteArrayOutputStream result = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; while(true) { int length = file.read(buffer); if(length == -1) break; result.write(buffer, 0, length); } file.close(); return result; } static public String readUTF8FromStream(InputStream file) throws IOException { ByteArrayOutputStream result = readDataFromStream(file); if(result == null) return null; try { return result.toString("UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } }
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Bipin@Amazon avatar image
Bipin@Amazon answered
Hi Bgglenn, The HttpURLConnection object has to be closed and release before exiting the HttpConnection operation method. Try using the final block as shown below: HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); try { OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); // Write the request. InputStream in = new BufferedInputStream(urlConnection.getInputStream()); // Read the result. [i] finally { urlConnection.disconnect(); }[/i] } Hope this info helps.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi bgglenn, We'd like you to send us your logs so we can get a better sense of what's going on with your implementation, and recognize that the forums cannot currently accomodate an attachment. Please visit the ContactUs form https://developer.amazon.com/help/contactus.html , and in the body of the message, include the the link to this thread ( https://forums.developer.amazon.com/forums/thread.jspa?threadID=1004) and indicate that you've been asked to provide us logs. We will respond to your contact with a mechanism by which you can deliver the logs to us. We will acknowledge receipt and then follow up in the context of this forum thread.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bgglenn avatar image
bgglenn answered
> The HttpURLConnection object has to be closed and > release before exiting the HttpConnection operation > method. I don't believe this is an issue with my app, because even if I kill the app completely, I still can't access the host from any other app, even the Amazon browser or from ping in an adb shell. The problem persists until the device is powered down and restarted. > We'd like you to send us your logs so we can get a better sense of what's going on with your implementation, and recognize that the forums cannot currently accomodate an attachment. I'll do that. Thanks.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bgglenn avatar image
bgglenn answered
FYI, I've also applied the disconnected() suggestion. I won't know for some time if this has any effect, since the issue only happens every few days. If it does, there's still an OS-level issue, but it would no longer be a critical one for us.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

bgglenn avatar image
bgglenn answered
Some data points: - The issue is still happening after adding the disconnect() call. - It persists through disconnecting and reconnecting wifi. It also persists through power cycling the AP. Only power cycling the tablet fixes the issue. shell@android:/ $ ping 23.21.133.162 ping 23.21.133.162 PING 23.21.133.162 (23.21.133.162) 56(84) bytes of data. From 192.168.1.5 icmp_seq=2 Destination Host Unreachable From 192.168.1.5 icmp_seq=3 Destination Host Unreachable From 192.168.1.5 icmp_seq=4 Destination Host Unreachable From 192.168.1.5 icmp_seq=5 Destination Host Unreachable From 192.168.1.5 icmp_seq=6 Destination Host Unreachable Other hosts are reachable: shell@android:/ $ ping 8.8.8.8 ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=46 time=27.2 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=25.2 ms 192.168.1.5 is the IP of the tablet. 23.21.133.162 is reachable from other hosts on the same network.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Bgglenn, Thank you for the information. We are looking at your issue. As we have a case opened in ContactUs, let's use that for further communication.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mobulagames avatar image
mobulagames answered
I believe I have the same issue with my socket based game where it is failing submission only on the Kindle Fire HD 7. I can not reproduce the issue on my end but the Amazon App Store Tester keep getting the error code for Host Unreachable.
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

mobulagames avatar image
mobulagames answered
Also wanted to state that I do have case numbers already. Case 105749261 and Case 105730731
10 |5000 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.