uncaught SocketTimeoutException issue

Hello,

Here is a sample code snippet:

                    try {
                        getModel().refreshFilters();
                        success = true;
                    } catch (IOException ioe) {
                        handleException(getView(), ioe, "Problem refreshing filter data.");
                    }

When running this code, my application throws an exception:

Caused by: java.net.SocketTimeoutException: Read timed out
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:149)
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:143)
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:111)

Shouldn't the SocketTimeoutException which is a sub-class of IOException be caught ?

Paolo
ptrevesAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CEHJConnect With a Mentor Commented:
>>Maybe introducing a delay in the Command Thread such as Thread.sleep(2000) ...

Yes, that's a possibility. Some code simply should not be executed too much in quick succession
0
 
for_yanCommented:
Are you sure it comes from this very place?
No methods refreshfiletern getMode are metioned.$
Add some printout ion the truy catch loop befiore calling method nd after caling
0
 
CEHJCommented:
Please post full output
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ptrevesAuthor Commented:
Here is the complete stack trace:

java.io.IOException: java.net.SocketTimeoutException: Read timed out
java.io.IOException: java.net.SocketTimeoutException: Read timed out
      at com.gepower.d400.communication.database.RecordDataFilterLoader.populateRecordFilterManager(RecordDataFilterLoader.java:59)
      at com.gepower.d400.model.database.RecordFilterManager.refresh(RecordFilterManager.java:68)
      at com.gepower.d400.view.runtime.database.ReportModel.refreshFilters(ReportModel.java:493)
      at com.gepower.d400.view.runtime.database.ReportController$RefreshFiltersAction$1.doLongOperation(ReportController.java:307)
      at com.gepower.d400.swing.BusyThread.run(BusyThread.java:103)
Caused by: com.gepower.d400.communication.RequestException: java.net.SocketTimeoutException: Read timed out
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:149)
      at com.gepower.d400.communication.database.RecordDataFilterLoader.populateRecordFilterManager(RecordDataFilterLoader.java:57)
      ... 4 more
Caused by: java.net.SocketTimeoutException: Read timed out
      at sun.reflect.GeneratedConstructorAccessor38.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at java.net.HttpURLConnection.getResponseCode(Unknown Source)
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:143)
      ... 5 more
Caused by: java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.read(Unknown Source)
      at java.io.BufferedInputStream.fill(Unknown Source)
      at java.io.BufferedInputStream.read1(Unknown Source)
      at java.io.BufferedInputStream.read(Unknown Source)
      at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
      at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at java.net.HttpURLConnection.getResponseCode(Unknown Source)
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:111)
      ... 5 more
0
 
CEHJCommented:
>>Shouldn't the SocketTimeoutException which is a sub-class of IOException be caught ?

The result you're expecting will only happen if  no exceptions in threads other than the one executing your code occur. It's possibly fortunate for you, since you now have a proper stack trace to help you diagnose the actual cause of the problem, which could possibly be due to a network issue
0
 
ptrevesAuthor Commented:
The problem occurs randomly after a series of "Clear Logs" / "Refresh Filters" commands.
I get the impression that the exception is not caught for some reason.
0
 
CEHJCommented:
>>I get the impression that the exception is not caught for some reason.

See my first sentence in http:#36598646
0
 
ptrevesAuthor Commented:
Here is what I think the problem could be:

Both RequestException and ResponseException extend directly from the Exception calls. Here is an example for the Request Exception :

public class RequestException extends Exception{
    public RequestException(String message){
        super(message);
    }

    public RequestException(Exception e){
        super(e);        
    }
}

Here is a relationship hierarchy of the different exceptions:
Exception - RequestException
Exception - ResponseException
Exception - IOException - SocketTimeoutException

Looking through the code based on the StackTrace, I noted the following code snippet:
from line 111 in SyncRequest. java:

            int statusCode = connection.getResponseCode();

From line 143 in SyncRequest.java (connection.getResponseCode()):
            try {
                if (connection != null && connection.getResponseCode() != -1) {
                    throw new ResponseException(connection.getResponseCode(), getErrorMessage(connection), errorBody );
                } else {
                    throw new RequestException(e);
                }
            } catch (IOException ioe) {
                throw new RequestException(ioe);
            }


It seems that the method calls:

            int statusCode = connection.getResponseCode();

are throwing the exception. The execute method signature is the following:

    public void execute() throws RequestException, ResponseException {

All method calls to:             int statusCode = connection.getResponseCode();
are wrapped aroung and IOException in a catch block which you would expect to catch any sub-exception like
SocketTimeoutException

Maybe that would be the fix ?

Paolo
0
 
for_yanCommented:

I understand that this exception
Caused by: com.gepower.d400.communication.RequestException: java.net.SocketTimeoutException: Read timed out

would not be caught by catch(IOException) because RequestException does not inherit from IOException

but I still don't understand why this exception

java.io.IOException: java.net.SocketTimeoutException: Read timed out

would not be caught?

When you are writing your own exceptions

RequestException and ResponseException - can't you extend these from IOExceptiion rather than Exception ?



0
 
CEHJCommented:
Could you please post the full code for the method handleException?
0
 
ptrevesAuthor Commented:


    /**
     * Shows a modal <code>ErrorDialog</code> with the Application Error title over the specified parent
     * with the specified message, and exception.
     * <p/>
     * This method is thread safe, although most Swing methods are not.
     *
     * @param parent    - parent to display dialog over
     * @param exception - exception to show stack of
     * @param message   - message to display to user
     */
    public void handleException(Component parent, Throwable exception, String message) {
        ErrorDialog.showErrorDialog(parent, exception, message);
    }

0
 
CEHJCommented:
That's slightly strange. Normally exceptions should be ... exceptional, so it's not usual to present them to the user in a dialog. You should really log them, with full stack trace.
Just to recap, is the stack trace at http:#36598621 the one that occurs?
0
 
CEHJCommented:
>>so it's not usual to present them to the user in a dialog.

Of course the word 'not' shouldn't be present in the above ;)
0
 
ptrevesAuthor Commented:
yes, that is the stack trace generated.
0
 
CEHJCommented:
OK - forgive me for asking more questions, but i feel there's a lack of clarity here: do i take it that your goal is to solve the problem that's causing this exception?
0
 
ptrevesAuthor Commented:
yes, absolutely.
0
 
CEHJCommented:
It looks like either

a. an issue with the network (eliminate that by attempting to connect to different hosts)
b. an issue with that particular server (see a.)
0
 
ptrevesAuthor Commented:
I extended RequestException and ResponseException both from IOException instead of Exception.
I still got this Stack Trace:

java.io.IOException: java.net.SocketTimeoutException: Read timed out
java.io.IOException: java.net.SocketTimeoutException: Read timed out
      at com.gepower.d400.communication.database.RecordDataFilterLoader.populateRecordFilterManager(RecordDataFilterLoader.java:59)
      at com.gepower.d400.model.database.RecordFilterManager.refresh(RecordFilterManager.java:68)
      at com.gepower.d400.view.runtime.database.ReportModel.refreshFilters(ReportModel.java:493)
      at com.gepower.d400.view.runtime.database.ReportController$RefreshFiltersAction$1.doLongOperation(ReportController.java:309)
      at com.gepower.d400.swing.BusyThread.run(BusyThread.java:103)
Caused by: com.gepower.d400.communication.RequestException: java.net.SocketTimeoutException: Read timed out
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:149)
      at com.gepower.d400.communication.database.RecordDataFilterLoader.populateRecordFilterManager(RecordDataFilterLoader.java:57)
      ... 4 more
Caused by: java.net.SocketTimeoutException: Read timed out
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at java.net.HttpURLConnection.getResponseCode(Unknown Source)
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:143)
      ... 5 more
Caused by: java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method)
      at java.net.SocketInputStream.read(Unknown Source)
      at java.io.BufferedInputStream.fill(Unknown Source)
      at java.io.BufferedInputStream.read1(Unknown Source)
      at java.io.BufferedInputStream.read(Unknown Source)
      at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
      at sun.net.www.http.HttpClient.parseHTTP(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
      at java.net.HttpURLConnection.getResponseCode(Unknown Source)
      at com.gepower.d400.communication.SyncRequest.execute(SyncRequest.java:111)
      ... 5 more

0
 
CEHJCommented:
Yes, the reason for the exception, and its cure, are nothing to do with the type of your Exception
0
 
ptrevesAuthor Commented:
This bug occurs periodially when pressing a compination of the command buttons "Refresh Filters" and "Clear Logs" in rapid succession over and over again.

Maybe introducing a delay in the Command Thread such as Thread.sleep(2000); or something would allow proper packet transfer and avoid any such Exceptions ?

0
 
for_yanCommented:
Maybe you could increase the timeout time?

Are you connecting in your own code - in this case you can use connect with timeout paparmeter method:
http://download.oracle.com/javase/1.4.2/docs/api/java/net/Socket.html#connect%28java.net.SocketAddress,%20int%29
0
 
ptrevesAuthor Commented:
There is a parameter called: SO_TIMEOUT (or DEFAULT_READ_TIMEOUT)
It's value is set to: 10000.
Another parmeter called READ_TIMEOUT=60000

I adjusted the values to 30000 and 40/60000 respectivily. with some improvements.
After numerous attemps, other kinds of exceptions get generated.
0
 
for_yanCommented:
>other kinds of exceptions get generated

You mean not timeout, but other kinds of exceptions ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.