SocketException at startup and close

Help
2011-10-24
2012-09-23
  • Radoslav Bielik

    Radoslav Bielik - 2011-10-24

    Hi there! I'm currently testing your library, since we need to embed a web-
    browser component into our application, and other frameworks didn't work well
    with the website we need to access. However, I'm running into some
    SocketExceptions all the time.

    First things first: I'm testing version 1-0-2-20110904 with the enclosed SWT
    swt-3.7M5-win32-win32-x86.jar (working on 32-bit Windows Vista). I'm facing 2
    separate issues:

    1) a SocketException: Connection reset being always printed into stdout
    everytime we close our application.
    2) a SocketException: Connection reset being sometimes thrown when the
    application is started

    Issue #1: I'd like to know if the exception when the app is being closed can be avoided somehow? Seeing an exception makes me believe we need to do some proper shutdown procedure or something. Also, even worse, in 60-70% of the time, the java.exe process that is being spawned is not stopped when the application is closed. After several runs, this results in numerous java.exe processes (taking up to 7MB each) hanging in the system. With my quick testing, the process is not stopped in 3 or 4 of 5 application starts.

    I found out that if I call
    NativeInterface.getConfiguration().setNativeSideRespawnedOnError(false)
    before calling NativeInterface.open(), the exception is still being printed,
    but the process is always being closed properly. But as I read in another
    forum topic, this is not recommended.

    Issue #2: Sometimes when the app is started, our exception manager will catch a SocketException and the app won't start. This happens randomly, perhaps once in 20 or 30 application starts? Any idea what this is caused by, or if I'm doing anything wrong? Here's the stack trace of one of the occurrences:

    07:25:10.594 ERROR [main] QExceptionManager | java.lang.RuntimeException: java.net.SocketException: Connection reset
    java.lang.RuntimeException: java.net.SocketException: Connection reset
        at chrriis.dj.nativeswing.swtimpl.core.OutProcessSocketsMessagingInterface.openChannel(OutProcessSocketsMessagingInterface.java:67)
        at chrriis.dj.nativeswing.swtimpl.core.MessagingInterface.initialize(MessagingInterface.java:57)
        at chrriis.dj.nativeswing.swtimpl.core.OutProcessSocketsMessagingInterface.<init>(OutProcessSocketsMessagingInterface.java:32)
        at chrriis.dj.nativeswing.swtimpl.core.OutProcessSocketsMessagingInterface$SwingOutProcessSocketsMessagingInterface.<init>
    
    (OutProcessSocketsMessagingInterface.java:162)
        at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface$OutProcess.createOutProcessMessagingInterface(SWTNativeInterface.java:995)
        at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface$OutProcess.createOutProcessCommunicationChannel(SWTNativeInterface.java:738)
        at chrriis.dj.nativeswing.swtimpl.core.SWTNativeInterface.open_(SWTNativeInterface.java:321)
        at chrriis.dj.nativeswing.swtimpl.NativeInterface.open(NativeInterface.java:100)
        at com.qarbon.shasta.main.QViewletBuilderEnterpriseApp.main(QViewletBuilderEnterpriseApp.java:48)
    Caused by: java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:168)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
        at java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2266)
        at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
        at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750)
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280)
        at chrriis.dj.nativeswing.swtimpl.core.OutProcessSocketsMessagingInterface.openChannel(OutProcessSocketsMessagingInterface.java:65)
        ... 8 more
    07:25:10.726 ERROR [AWT-EventQueue-0] QExceptionManager | Unable to handle exception
    java.lang.NullPointerException
        at com.qarbon.shasta.util.QSystemUtilities.getUserDirectory(QSystemUtilities.java:398)
        at com.qarbon.shasta.exception.QExceptionManager$QHandler.handle(QExceptionManager.java:207)
        at com.qarbon.shasta.exception.QExceptionManager$QHandler.run(QExceptionManager.java:190)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    

    Thanks for any clues!

    Rado

     
  • Christopher Deckers

    Hi Rado,

    Issue #1: I'd like to know if the exception when the app is being closed can
    be avoided somehow?

    I don't think I see any exceptions when closing the application. Are you
    interacting with the component when that exception is shown?
    In any case, I can understand the exception being printed if the communication
    is interrupted which is possible while shutting down.

    Seeing an exception makes me believe we need to do some proper shutdown
    procedure or something.

    How exactly are you "closing"/"shuting down" the application?

    Also, even worse, in 60-70% of the time, the java.exe process that is being
    spawned is not stopped when the application is closed.

    I have never seen this. Are you calling "System.exit(x)" when the application
    is closed?

    Issue #2: Sometimes when the app is started, our exception manager will
    catch a SocketException and the app won't start.

    Could you activate that system property:
    -Dnativeswing.localhostAddress.debug.print=true
    An IP address gets printed to the console. Is it different in cases where you
    get the exception?

    Cheers,
    -Christopher

     
  • Radoslav Bielik

    Radoslav Bielik - 2011-10-26

    Chris, thank you for your reply!

    > I don't think I see any exceptions when closing the application. Are you
    interacting with the component when that exception is shown? In any case, I
    can understand the exception being printed if the communication is interrupted
    which is possible while shutting down.

    It seems the exception is being printed into stdout rather than being thrown.

    > How exactly are you "closing"/"shuting down" the application?

    Clicking the red 'x' :-) Sorry, this is a bigger project and I'm only working
    on some parts. I looked into this today and we have a handler to shut down the
    application (it's called whether you do a File-Exit or close the main window)
    which first does some event procesing and at the end it calls System.exit(0);

    While testing today, interestingly, the issue with the hanging java.exe
    process occurred only in about 10% of cases so it wasn't as bad as a few days
    ago. Not sure what is affecting it, since there were no changes made to the
    application.

    > An IP address gets printed to the console. Is it different in cases where
    you get the exception?

    I did this but so far the startup exception didn't occur. It was 127.0.0.1 in
    all cases. I'll keep watching.

     
  • Radoslav Bielik

    Radoslav Bielik - 2011-10-26

    Forgot to answer this:

    > Are you interacting with the component when that exception is shown?

    No, it happens even if I just launch and close the app and never use the
    components.

     
  • Christopher Deckers

    Clicking the red 'x' :-)
    I looked into this today and we have a handler to shut down the application
    which first does some event procesing and at the end it calls System.exit(0);

    I am not sure why you get an exception, because it seems it tries to re-
    connect the interface. But I don't see why the interface needs to be
    reconnected since you don't seem to close it or have any particular action
    that kills the other process.

    While testing today, interestingly, the issue with the hanging java.exe
    process occurred only in about 10% of cases

    Still, I have never seen such condition before...

    When you click the X, do you perfom lots of operations in the UI thread?

    -Christopher

     
  • John Oates

    John Oates - 2011-12-08

    Rado,

    Did you ever figure out what was going on. I'm having the issue you describe
    (#1) when closing my application.

    Here's the exception dump in stdout:

    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
    at java.io.ObjectInputStream$PeekInputStream.peek(ObjectInputStream.java:2200)
    at java.io.ObjectInputStream$BlockDataInputStream.peek(ObjectInputStream.java:
    2490)
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.j
    ava:2500)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)
    at java.io.ObjectInputStream.readUnshared(ObjectInputStream.java:431)
    at chrriis.dj.nativeswing.swtimpl.core.OutProcessSocketsMessagingInterface.rea
    dMessageFromChannel(OutProcessSocketsMessagingInterface.java:116)
    at chrriis.dj.nativeswing.swtimpl.core.MessagingInterface$2.run(MessagingInter
    face.java:388)

    Thanks for any help!
    - John

     
  • Radoslav Bielik

    Radoslav Bielik - 2011-12-08

    John, sorry, we've decided to take a different approach so that we don't have
    to embed additional libraries into our project. While I was curious enough to
    try & resolve this issue I didn't have enough time to work on this, so no - I
    didn't resolve it.

     
  • Christopher Deckers

    Hi John,

    When closing the application, it sometimes happens that the native component
    was communicating events or something. When this happens, the communication is
    abruptly interrupted which writes to the console, but it is not really a
    problem.

    -Christopher

     
  • John Oates

    John Oates - 2011-12-11

    Christopher,

    True, except as Rado observed, sometimes the process never actually exits and
    you end up with one or more instances of java runtime executing in your task
    manager after you've supposedly closed the application. I think I've been able
    to tie it to the fact that I'm running a flash video, and it seems to be
    resolved if I navigate to some static html page upon receiving the shutdown
    hook. I'll report back with any other relevant information.

    By the way, you've done a great job with this utility. It has obviously been
    useful to many people and your product support is better than most I've seen
    on the internet. Thank you, and Keep it up!!

    • John
     
  • John Oates

    John Oates - 2011-12-14

    Well - I won't know for sure until I've tested it a million more times, but I
    think I found the problem. And if I'm right, my face is a little red right
    now. I was never calling NativeInterface.close(). I searched my code and when
    I didn't see that function call anywhere I added it to the shutdown hook. So
    far the application has closed gracefully every time. Hopefully this
    information helps someone else!

     
  • Christopher Deckers

    I was never calling NativeInterface.close()

    And you should not need to, it should auto close when the main program exits.
    I need to find the time to investigate this issue...

    -Christopher

     
  • Christopher Deckers

    Hi,

    I just uploaded: DJNativeSwing-SWT-1-0-2-20111218.zip

    I think I found the reason for the non-terminating peer process. This version
    should fix it, so there is no need to call an explicit close when terminating
    the application.

    Hope this helps,
    -Christopher

     
  • Eric Lopez

    Eric Lopez - 2012-03-20

    Hi Chris,

    I am using your library in a project I'm working on and it is giving me an
    exception similar to the one posted by John.

    Here is the log.

    07:13:58.175 <W> <STDERR> java.net.SocketException: Connection reset
    07:13:58.175 <W> <STDERR> at java.net.SocketInputStream.read(Unknown Source)
    07:13:58.175 <W> <STDERR> at java.io.BufferedInputStream.fill(Unknown Source)
    07:13:58.175 <W> <STDERR> at java.io.BufferedInputStream.read(Unknown Source)
    07:13:58.175 <W> <STDERR> at
    java.io.ObjectInputStream$PeekInputStream.peek(Unknown Source)
    07:13:58.175 <W> <STDERR> at
    java.io.ObjectInputStream$BlockDataInputStream.peek(Unknown Source)
    07:13:58.175 <W> <STDERR> at
    java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    07:13:58.175 <W> <STDERR> at java.io.ObjectInputStream.readObject0(Unknown
    Source)
    07:13:58.175 <W> <STDERR> at java.io.ObjectInputStream.readUnshared(Unknown
    Source)
    07:13:58.175 <W> <STDERR> at chrriis.dj.nativeswing.swtimpl.core.OutProcessSoc
    ketsMessagingInterface.readMessageFromChannel(OutProcessSocketsMessagingInterf
    ace.java:116)
    07:13:58.175 <W> <STDERR> at chrriis.dj.nativeswing.swtimpl.core.MessagingInte
    rface$2.run(MessagingInterface.java:378)

    Did you ever find a solution for that problem?

    Thank you very much for this awesome library!

    Kind regards,
    Eric López

     
  • Christopher Deckers

    Hi Eric,

    This exception is a generic exception that can occur for various reasons. It
    basically happens when the communication with the process that I spawn to
    handle native components gets interrupted.
    The exception itself is not enough to understand why it got interrupted. The
    reason could be a crash of the native component that killed the native process
    in which case upgrading your web browser (Internet Explorer) could help solve
    some crashes for example. But it could be for other reasons.

    Hope this helps,
    -Christopher

     
  • Eric Lopez

    Eric Lopez - 2012-04-19

    Hi Chris,

    I added the -Dnativeswing.localhostAddress.debug.print=true argument to the VM
    and here is the extra Information I am getting:

    16:09:08.602 <W> <STDERR> java.net.SocketException: Connection reset
    16:09:08.603 <W> <STDERR> at java.net.SocketInputStream.read(Unknown Source)
    16:09:08.603 <W> <STDERR> at java.io.BufferedInputStream.fill(Unknown Source)
    16:09:08.603 <W> <STDERR> at java.io.BufferedInputStream.read(Unknown Source)
    16:09:08.603 <W> <STDERR> at
    java.io.ObjectInputStream$PeekInputStream.peek(Unknown Source)
    16:09:08.603 <W> <STDERR> at
    java.io.ObjectInputStream$BlockDataInputStream.peek(Unknown Source)
    16:09:08.603 <W> <STDERR> at
    java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    16:09:08.603 <W> <STDERR> at java.io.ObjectInputStream.readObject0(Unknown
    Source)
    16:09:08.603 <W> <STDERR> at java.io.ObjectInputStream.readUnshared(Unknown
    Source)
    16:09:08.603 <W> <STDERR> at chrriis.dj.nativeswing.swtimpl.core.OutProcessSoc
    ketsMessagingInterface.readMessageFromChannel(OutProcessSocketsMessagingInterf
    ace.java:116)
    16:09:08.603 <W> <STDERR> at chrriis.dj.nativeswing.swtimpl.core.MessagingInte
    rface$2.run(MessagingInterface.java:378)
    16:09:08.605 <W> <STDERR> Native Command:

    Does it tell you something? The application is installed on a computer running
    Windows 7, the user has full-admin rights, the browser is up to date. I really
    don't know what might be wrong.

    Thank you so much for your help!
    Eric López

     
  • Christopher Deckers

    Hi Eric,

    What you are showing me is not the output produced by activating
    "-Dnativeswing.localhostAddress.debug.print=true", but rather
    "-Dnativeswing.peervm.debug.printCommandLine=true". Well, it does not matter
    because I see the IP address that is used.

    Is it running on a 64bit JVM? Do you have any particular proxy / VPN in place?

    -Christopher

     
  • Eric Lopez

    Eric Lopez - 2012-04-30

    Hi Christopher,

    It is running a 32-bit JVM. There are no proxies, I also tested disabling any
    type of antivirus or firewall, the user has Windows 7, a recent browser and
    Adobe Flash player is up to date.

    The exception is thrown initially by the following code:

    @Override
    protected Message readMessageFromChannel() throws IOException,
    ClassNotFoundException {
    Object o = ois.readUnshared();
    if(o instanceof Message) {
    Message message = (Message)o;
    if(IS_DEBUGGING_MESSAGES) {
    System.err.println("RECV: " + SWTNativeInterface.getMessageID(message) + ", "
    + message);
    }
    return message;
    }
    System.err.println("Unknown message: " + o);
    return null;
    }

    Somehow Object o = ois.readUnshared(); ends up throwing the

    16:33:48.529 <W> <STDERR> java.net.SocketException: Connection reset
    16:33:48.530 <W> <STDERR> at java.net.SocketInputStream.read(Unknown Source)
    16:33:48.530 <W> <STDERR> at java.io.BufferedInputStream.fill(Unknown Source)
    16:33:48.530 <W> <STDERR> at java.io.BufferedInputStream.read(Unknown Source)
    16:33:48.530 <W> <STDERR> at
    java.io.ObjectInputStream$PeekInputStream.peek(Unknown Source)
    16:33:48.530 <W> <STDERR> at
    java.io.ObjectInputStream$BlockDataInputStream.peek(Unknown Source)
    16:33:48.530 <W> <STDERR> at
    java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    16:33:48.530 <W> <STDERR> at java.io.ObjectInputStream.readObject0(Unknown
    Source)
    16:33:48.530 <W> <STDERR> at java.io.ObjectInputStream.readUnshared(Unknown
    Source)
    16:33:48.530 <W> <STDERR> at chrriis.dj.nativeswing.swtimpl.core.OutProcessSoc
    ketsMessagingInterface.readMessageFromChannel(OutProcessSocketsMessagingInterf
    ace.java:116)
    16:33:48.530 <W> <STDERR> at chrriis.dj.nativeswing.swtimpl.core.MessagingInte
    rface$2.run(MessagingInterface.java:378)

    Have you seen that problem before?

    Thank you very much for your help!
    Eric López

     
  • Christopher Deckers

    Hi Eric,

    I am not sure what is causing the problem on your system... Are you using a
    recent 1.0.2 preview of DJ Native Swing? Did you try with SWT 3.8M5?

    Cheers,
    -Christopher

     
  • Aking

    Aking - 2012-05-22

    Perhaps you could change your jvm version to resolve this problem. We met this
    error with jvm 1.7 and resolve it by changing jvm to version 1.6.

    Hope it's helpful to you.

    Cheers,
    -Aking

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks