Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy would a "java.net.ConnectException: Connection timed out" exception occur when URL is up?
    primarykey
    data
    text
    <p>I'm getting a <code>ConnectException: Connection timed out</code> with some frequency from my code. The URL I am trying to hit is up. The same code works for some users, but not others. It seems like once one user starts to get this exception they continue to get the exception.</p> <p>Here is the stack trace:</p> <pre><code>java.net.ConnectException: Connection timed out Caused by: java.net.ConnectException: Connection timed out at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.Socket.connect(Socket.java:516) at java.net.Socket.connect(Socket.java:466) at sun.net.NetworkClient.doConnect(NetworkClient.java:157) at sun.net.www.http.HttpClient.openServer(HttpClient.java:365) at sun.net.www.http.HttpClient.openServer(HttpClient.java:477) at sun.net.www.http.HttpClient.&lt;init&gt;(HttpClient.java:214) at sun.net.www.http.HttpClient.New(HttpClient.java:287) at sun.net.www.http.HttpClient.New(HttpClient.java:299) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:796) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:748) at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:673) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:840) </code></pre> <p>Here is a snippet from my code:</p> <pre><code>URLConnection urlConnection = null; OutputStream outputStream = null; OutputStreamWriter outputStreamWriter = null; InputStream inputStream = null; try { URL url = new URL(urlBase); urlConnection = url.openConnection(); urlConnection.setDoOutput(true); outputStream = urlConnection.getOutputStream(); // exception occurs on this line outputStreamWriter = new OutputStreamWriter(outputStream); outputStreamWriter.write(urlString); outputStreamWriter.flush(); inputStream = urlConnection.getInputStream(); String response = IOUtils.toString(inputStream); return processResponse(urlString, urlBase, response); } catch (IOException e) { throw new Exception("Error querying url: " + urlString, e); } finally { IoUtil.close(inputStream); IoUtil.close(outputStreamWriter); IoUtil.close(outputStream); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload