MINA
  1. MINA
  2. DIRMINA-379

setKeepAlive/setTcpNoDelay and exceptions in Windows Vista

    Details

    • Type: Bug Bug
    • Status: Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.0.3, 1.1.0, 2.0.0-M1
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None
    • Environment:
      Windows Vista Home Premium Italian
      Java SE 1.5.0_11, Java SE 1.6 Update 1, Java SE 1.4.2_12

      Description

      When I ran my application under Vista I get this exception:

      Exception in thread "Thread-4" org.apache.mina.common.RuntimeIOException: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
      at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:252)
      at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:94)
      at org.apache.mina.transport.socket.nio.SocketConnector.newSession(SocketConnector.java:350)
      at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:290)
      at org.apache.mina.transport.socket.nio.SocketConnector.access$900(SocketConnector.java:53)
      at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:395)
      at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
      at sun.nio.ch.Net.setIntOption0(Native Method)
      at sun.nio.ch.Net.setIntOption(Net.java:152)
      at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:372)
      at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
      at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92)
      at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139)
      at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322)
      at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:248)
      ... 7 more

      I had to remove the following lines from the SocketSessionImpl constructor:
      this.config.setKeepAlive( cfg.isKeepAlive() );
      this.config.setTcpNoDelay( cfg.isTcpNoDelay() );
      and now it works.

      No matter if I change the configuration to let them return true or false, I keep getting the exception if I don't remove the call at all.

        Activity

        Hide
        Brett Wooldridge added a comment -

        Another data point. This error is not limited to Windows, we just saw this on Mac OS X 10.7 (Lion).

        Show
        Brett Wooldridge added a comment - Another data point. This error is not limited to Windows, we just saw this on Mac OS X 10.7 (Lion).
        Hide
        Rob Eden added a comment -

        FYI, I do still see this on Java 1.7.0_01.

        Show
        Rob Eden added a comment - FYI, I do still see this on Java 1.7.0_01.
        Hide
        Rob Eden added a comment -

        Note for the above I added the MultiConnectTest.java attachment.

        Show
        Rob Eden added a comment - Note for the above I added the MultiConnectTest.java attachment.
        Rob Eden made changes -
        Attachment MultiConnectTest.java [ 12503815 ]
        Hide
        Rob Eden added a comment -

        This is a unit test that demonstrates the problem very frequently on my system (Windows 7 Enterprise, SP1/JDK 1.6.0_26).

        The unit test is for my RMI-like framework called Intrepid, so you'll need the binaries for that (https://sourceforge.net/projects/intrepid2/files/release/)
        The unit test also hits other exceptions, but you should hit this error pretty frequently. With the 1.0.4 release (using MINA 2.0.3), I'm hitting it about half the time.

        My arguments to run the test (will vary slightly based on where you place things, obviously): java -cp out\test\Int
        repid;dist\intrepid-1.0.4.jar;lib\mina-core-2.0.3.jar;lib\trove-3.0.0.jar;lib\test\junit-4
        .8.1.jar;lib\starlight-common-250.jar;lib\slf4j-api-1.6.1.jar junit.textui.TestRunner com.
        starlight.intrepid.MultiConnectTest

        Show
        Rob Eden added a comment - This is a unit test that demonstrates the problem very frequently on my system (Windows 7 Enterprise, SP1/JDK 1.6.0_26). The unit test is for my RMI-like framework called Intrepid, so you'll need the binaries for that ( https://sourceforge.net/projects/intrepid2/files/release/ ) The unit test also hits other exceptions, but you should hit this error pretty frequently. With the 1.0.4 release (using MINA 2.0.3), I'm hitting it about half the time. My arguments to run the test (will vary slightly based on where you place things, obviously): java -cp out\test\Int repid;dist\intrepid-1.0.4.jar;lib\mina-core-2.0.3.jar;lib\trove-3.0.0.jar;lib\test\junit-4 .8.1.jar;lib\starlight-common-250.jar;lib\slf4j-api-1.6.1.jar junit.textui.TestRunner com. starlight.intrepid.MultiConnectTest
        Hide
        Rob Eden added a comment -

        I'm seeing this problem on Windows 7 with MINA 2.0.3.

        Show
        Rob Eden added a comment - I'm seeing this problem on Windows 7 with MINA 2.0.3.
        Hide
        Suhas Sutar added a comment -

        Appreciate the prompt reply. Can you please confirm that this issue has not been fixed in latest versions of MINA?

        Show
        Suhas Sutar added a comment - Appreciate the prompt reply. Can you please confirm that this issue has not been fixed in latest versions of MINA?
        Hide
        Edouard De Oliveira added a comment -

        according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7058336
        it may be due to a jdk 1.5 & 1.6 bug it says jdk 1.7 has a rewritten Socket adaptator
        maybe you can try jdk 1.7 to check if it solves the issue
        dirty hack would be to try to delay as much as possible the socket options setting to prevent options to be set on a non open socket

        please note we are not releasing 1.x versions anymore

        Show
        Edouard De Oliveira added a comment - according to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7058336 it may be due to a jdk 1.5 & 1.6 bug it says jdk 1.7 has a rewritten Socket adaptator maybe you can try jdk 1.7 to check if it solves the issue dirty hack would be to try to delay as much as possible the socket options setting to prevent options to be set on a non open socket please note we are not releasing 1.x versions anymore
        Hide
        Suhas Sutar added a comment -

        Guys,
        I am using v1.1.7 and need to address this issue for my application. I cannot upgrade because of my timelines but upgrading is not going to help as this seem to be still unresolved. I am looking for some suggestions.
        Thanks in advance!

        Show
        Suhas Sutar added a comment - Guys, I am using v1.1.7 and need to address this issue for my application. I cannot upgrade because of my timelines but upgrading is not going to help as this seem to be still unresolved. I am looking for some suggestions. Thanks in advance!
        Hide
        christopher kingsbury added a comment -

        FYI, I see this issue with 2.0.1 on windows 7. Disabling SocketTcpNoDelay resolves the issue, but I suspect will hurt performance in my particular case when running on Windows.

        Show
        christopher kingsbury added a comment - FYI, I see this issue with 2.0.1 on windows 7. Disabling SocketTcpNoDelay resolves the issue, but I suspect will hurt performance in my particular case when running on Windows.
        Hide
        Julien Vermillard added a comment -

        is it still a problem with 2.0.0 RC1 ?

        Show
        Julien Vermillard added a comment - is it still a problem with 2.0.0 RC1 ?
        Hide
        Barry Kaplan added a comment -

        Is there any workaround for this with the 1.1.7 ??

        Show
        Barry Kaplan added a comment - Is there any workaround for this with the 1.1.7 ??
        Hide
        Emmanuel Lecharny added a comment -

        Is there anything we can do before 2.0-RC1 ?

        Show
        Emmanuel Lecharny added a comment - Is there anything we can do before 2.0-RC1 ?
        Mauritz Lovgren made changes -
        Comment [ I see this as well (Windows 2000, 2003 Server and Vista), but only when reusing one SocketConnector for many client sessions, connecting clients very quickly in sequence.

        If I create a new SocketConnector instance for every client connection, the problem goes away. If this is due to the overhead of creating a new SocketConnector for each client, I do not know. I imagined one SocketConnector was multi-thread safe for creating many client connections in parallell (ref. the connectQueue etc ..) ?

        For the record, using MINA 1.1.7. Am a bit reluctant to go for MINA 2 in our production environment since it is not stable yet... ]
        Hide
        Trustin Lee added a comment -

        Stefano, you are using MINA 1.x, right? MINA 2 has optimized the system calls related with socket parameters for fater initialization, so it shouldn't have this issue unless you changed any socket parameters.

        Show
        Trustin Lee added a comment - Stefano, you are using MINA 1.x, right? MINA 2 has optimized the system calls related with socket parameters for fater initialization, so it shouldn't have this issue unless you changed any socket parameters.
        Hide
        Stefano Bagnara added a comment -

        I see it in a Vista box, never saw it Linux Windows XP.

        The weird thing is that if I remove any call to keepAlive, reuseAddress and tcpNoDelay the application works fine without exception and at full speed under vista!!

        I hope mina can do something to make my app working in Vista without having to run my own "hacked" mina version. Unfortunately I don't really have the needed skills (network knowledge) to provide a good patch (my patch simply remove all the set/get for the above properties).

        Show
        Stefano Bagnara added a comment - I see it in a Vista box, never saw it Linux Windows XP. The weird thing is that if I remove any call to keepAlive, reuseAddress and tcpNoDelay the application works fine without exception and at full speed under vista!! I hope mina can do something to make my app working in Vista without having to run my own "hacked" mina version. Unfortunately I don't really have the needed skills (network knowledge) to provide a good patch (my patch simply remove all the set/get for the above properties).
        Hide
        Trustin Lee added a comment -

        It's a Windows-only issue according to Alan. I forgot the exact reason, but it's due to the recent changes in Windows networking stack.

        Show
        Trustin Lee added a comment - It's a Windows-only issue according to Alan. I forgot the exact reason, but it's due to the recent changes in Windows networking stack.
        Hide
        Sangjin Lee added a comment -

        I also see this issue on Windows 2003 Server... Which makes me curious. Is this a cross-platform issue or specific to some flavors of Windows? From Alan B's comments, it sounds like a generic issue with these methods?

        Show
        Sangjin Lee added a comment - I also see this issue on Windows 2003 Server... Which makes me curious. Is this a cross-platform issue or specific to some flavors of Windows? From Alan B's comments, it sounds like a generic issue with these methods?
        Hide
        Trustin Lee added a comment -

        I met Alan Bateman, the NIO.2 lead, and he told me that there's no clean solution for this issue for now. Probably we should close the connection when we fail to configure the socket in Windows? NIO.2 will fix this issue though.

        Show
        Trustin Lee added a comment - I met Alan Bateman, the NIO.2 lead, and he told me that there's no clean solution for this issue for now. Probably we should close the connection when we fail to configure the socket in Windows? NIO.2 will fix this issue though.
        Hide
        Stefano Bagnara added a comment -

        I tried adding isOpen and isConnected output to the exception by altering the SocketSessionImpl.setKeepAlive (mina 1.1.8-SNAPSHOT) this way:
        public void setKeepAlive(boolean on) {
        boolean isConnected = ch.isConnected();
        boolean isOpen = ch.isOpen();
        try

        { ch.socket().setKeepAlive(on); }

        catch (SocketException e)

        { throw new RuntimeIOException("setKeepAlive error isOpen: "+isOpen+"/"+ch.isOpen()+" isConnected: "+isConnected+"/"+ch.isConnected(), e); }

        }

        The result is this exception:

        1513 [AnonymousIoService-8] WARN org.apache.mina.common.support.DefaultExceptionMonitor - Unexpected exception.
        org.apache.mina.common.RuntimeIOException: setKeepAlive error isOpen: true/true isConnected: true/true
        at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:238)
        at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:101)
        at org.apache.mina.transport.socket.nio.SocketConnector.newSession(SocketConnector.java:341)
        at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:295)
        at org.apache.mina.transport.socket.nio.SocketConnector.access$800(SocketConnector.java:53)
        at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:383)
        at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
        at java.lang.Thread.run(Thread.java:619)
        Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
        at sun.nio.ch.Net.setIntOption0(Native Method)
        at sun.nio.ch.Net.setIntOption(Net.java:154)
        at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406)
        at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
        at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92)
        at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268)
        at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139)
        at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322)
        at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:236)
        ... 7 more

        So the channel is OPEN and CONNECTED.

        Furthermore I logged the exception from the MINA test failure:

        Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.043 sec
        Running org.apache.mina.transport.socket.nio.SocketBindTest
        9357 [SocketAcceptor-8] WARN org.apache.mina.common.support.DefaultExceptionMonitor - Unexpected exception.
        org.apache.mina.common.RuntimeIOException: setKeepAlive error isOpen: true/true
        isConnected: true/true
        at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:238)
        at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:101)
        at org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.processSessions(SocketAcceptor.java:283)
        at org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run(SocketAcceptor.java:225)
        at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
        at java.lang.Thread.run(Thread.java:619)
        Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
        at sun.nio.ch.Net.setIntOption0(Native Method)
        at sun.nio.ch.Net.setIntOption(Net.java:154)
        at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406)
        at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
        at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92)
        at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268)
        at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139)
        at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322)
        at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:236)
        ... 5 more
        Tests run: 5, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 7.677 sec <<< FAILURE!

        Tests in error:
        testUnbindDisconnectsClients(org.apache.mina.transport.socket.nio.SocketBindTest)

        The fact that also the mina test also fails from time to time let me hope that this is not an issue in my code!

        I also tried to alter the order of the setkeepAlive/setReuseAddress as suggested by Daniel Wirtz in the previous comment but it didn't fix the issue in my app: I still get the same very exception on the setKeepAlive. The only difference is that I get the exception few seconds later.

        Unfortunately I'm not able to create a small test that always fail. The good news (or bad??) is that my application fails 100% of the runs.

        I'm not sure I understand Alan message: is he saying that we have to report this to bugs.sun.com and that we cannot do anything to fix this in MINA? Isn't any workaround we can use to temporarily solve this issue?

        Show
        Stefano Bagnara added a comment - I tried adding isOpen and isConnected output to the exception by altering the SocketSessionImpl.setKeepAlive (mina 1.1.8-SNAPSHOT) this way: public void setKeepAlive(boolean on) { boolean isConnected = ch.isConnected(); boolean isOpen = ch.isOpen(); try { ch.socket().setKeepAlive(on); } catch (SocketException e) { throw new RuntimeIOException("setKeepAlive error isOpen: "+isOpen+"/"+ch.isOpen()+" isConnected: "+isConnected+"/"+ch.isConnected(), e); } } The result is this exception: 1513 [AnonymousIoService-8] WARN org.apache.mina.common.support.DefaultExceptionMonitor - Unexpected exception. org.apache.mina.common.RuntimeIOException: setKeepAlive error isOpen: true/true isConnected: true/true at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:238) at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:101) at org.apache.mina.transport.socket.nio.SocketConnector.newSession(SocketConnector.java:341) at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:295) at org.apache.mina.transport.socket.nio.SocketConnector.access$800(SocketConnector.java:53) at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:383) at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) at java.lang.Thread.run(Thread.java:619) Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption at sun.nio.ch.Net.setIntOption0(Native Method) at sun.nio.ch.Net.setIntOption(Net.java:154) at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406) at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38) at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92) at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268) at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139) at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322) at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:236) ... 7 more So the channel is OPEN and CONNECTED. Furthermore I logged the exception from the MINA test failure: Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.043 sec Running org.apache.mina.transport.socket.nio.SocketBindTest 9357 [SocketAcceptor-8] WARN org.apache.mina.common.support.DefaultExceptionMonitor - Unexpected exception. org.apache.mina.common.RuntimeIOException: setKeepAlive error isOpen: true/true isConnected: true/true at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:238) at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:101) at org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.processSessions(SocketAcceptor.java:283) at org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run(SocketAcceptor.java:225) at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) at java.lang.Thread.run(Thread.java:619) Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption at sun.nio.ch.Net.setIntOption0(Native Method) at sun.nio.ch.Net.setIntOption(Net.java:154) at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406) at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38) at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92) at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268) at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139) at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322) at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:236) ... 5 more Tests run: 5, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 7.677 sec <<< FAILURE! Tests in error: testUnbindDisconnectsClients(org.apache.mina.transport.socket.nio.SocketBindTest) The fact that also the mina test also fails from time to time let me hope that this is not an issue in my code! I also tried to alter the order of the setkeepAlive/setReuseAddress as suggested by Daniel Wirtz in the previous comment but it didn't fix the issue in my app: I still get the same very exception on the setKeepAlive. The only difference is that I get the exception few seconds later. Unfortunately I'm not able to create a small test that always fail. The good news (or bad??) is that my application fails 100% of the runs. I'm not sure I understand Alan message: is he saying that we have to report this to bugs.sun.com and that we cannot do anything to fix this in MINA? Isn't any workaround we can use to temporarily solve this issue?
        Trustin Lee made changes -
        Assignee Trustin Lee [ trustin ]
        Hide
        Trustin Lee added a comment -

        Too busy right now. Someone please fix it.

        Show
        Trustin Lee added a comment - Too busy right now. Someone please fix it.
        Hide
        Trustin Lee added a comment -

        A message from Alan Bateman:

        Trustin,

        I had a mail yesterday from someone that asked me to comment on this issue:
        https://issues.apache.org/jira/browse/DIRMINA-379

        I don't have a login on that site so I cannot reply but I see you are "Assignee" so I figured I would mail you.

        A long standing issue with the socket adapters is that they aren't synchronized with the closing of the channel. In order words, if you invoke methods on the Socket obtained from the socket channel's socket method then it does not throw an exception to indicate that the socket is closed. The typical error will be an "Invalid argument" error but it can vary by platform. For Windows Vista it will typically be an error to say the handle isn't a socket. We have replaced this code as part of the implementation of NIO2 so it will not be an issue in the future. I can't say for sure that your issue 379 is the same thing but if you can duplicate the problem easily then it would be great if you test if the channel is open or closed by invoking the isOpen method. If its closed that will explain the issue. If the channel is open then it may be an issue we haven't seen before, in which case it would be great if you could forward it to bugs.sun.com.

        Thanks,

        Alan.

        Show
        Trustin Lee added a comment - A message from Alan Bateman: Trustin, I had a mail yesterday from someone that asked me to comment on this issue: https://issues.apache.org/jira/browse/DIRMINA-379 I don't have a login on that site so I cannot reply but I see you are "Assignee" so I figured I would mail you. A long standing issue with the socket adapters is that they aren't synchronized with the closing of the channel. In order words, if you invoke methods on the Socket obtained from the socket channel's socket method then it does not throw an exception to indicate that the socket is closed. The typical error will be an "Invalid argument" error but it can vary by platform. For Windows Vista it will typically be an error to say the handle isn't a socket. We have replaced this code as part of the implementation of NIO2 so it will not be an issue in the future. I can't say for sure that your issue 379 is the same thing but if you can duplicate the problem easily then it would be great if you test if the channel is open or closed by invoking the isOpen method. If its closed that will explain the issue. If the channel is open then it may be an issue we haven't seen before, in which case it would be great if you could forward it to bugs.sun.com. Thanks, Alan.
        Hide
        Emmanuel Lecharny added a comment -

        Tanks guys !

        Seems that we are progressing in the good direction

        FYI, generating a diff is just as simple as typing this command :

        svn diff > diff.txt

        You have to be on the root of the MINA source directory (ie, if you did a svn co http://svn...(blah)/mina/trunk mina-2.0.0-M1, you have to be into mina-2.0.0-M1 directory to pass the command, so that the complete path will be stored into the diff file).

        Thanks !

        Show
        Emmanuel Lecharny added a comment - Tanks guys ! Seems that we are progressing in the good direction FYI, generating a diff is just as simple as typing this command : svn diff > diff.txt You have to be on the root of the MINA source directory (ie, if you did a svn co http://svn...(blah)/mina/trunk mina-2.0.0-M1, you have to be into mina-2.0.0-M1 directory to pass the command, so that the complete path will be stored into the diff file). Thanks !
        Hide
        Daniel Wirtz added a comment - - edited

        For 2.0.0-M1 the fix is:

        Change

        private static boolean DEFAULT_REUSE_ADDRESS = false;

        to

        private static boolean DEFAULT_REUSE_ADDRESS = true;

        in socket.DefaultSocketSessionConfig

        And change

        setKeepAlive(cfg.isKeepAlive());
        setOobInline(cfg.isOobInline());
        setReceiveBufferSize(cfg.getReceiveBufferSize());
        setReuseAddress(cfg.isReuseAddress());

        to

        setReuseAddress(cfg.isReuseAddress());
        setKeepAlive(cfg.isKeepAlive());
        setOobInline(cfg.isOobInline());
        setReceiveBufferSize(cfg.getReceiveBufferSize());

        in socket.AbstractSocketSessionConfig

        Seems to work as far as I can tell. Unfortunately I'm neigher familar with the 1.x branch nor with diff but maybe you can create a patch accordingly. The change applied to the default reuse behaviour is required, because the default values are set before anyone is able to override them inside the NioSessionConfig constructor.

        Edit: Oh, just looked around the sources again: I may be wrong with the default setting. But without changing it, the same app will work on xp/linux but not on vista without setting ReuseAddress explicitly.

        Show
        Daniel Wirtz added a comment - - edited For 2.0.0-M1 the fix is: Change private static boolean DEFAULT_REUSE_ADDRESS = false; to private static boolean DEFAULT_REUSE_ADDRESS = true; in socket.DefaultSocketSessionConfig And change setKeepAlive(cfg.isKeepAlive()); setOobInline(cfg.isOobInline()); setReceiveBufferSize(cfg.getReceiveBufferSize()); setReuseAddress(cfg.isReuseAddress()); to setReuseAddress(cfg.isReuseAddress()); setKeepAlive(cfg.isKeepAlive()); setOobInline(cfg.isOobInline()); setReceiveBufferSize(cfg.getReceiveBufferSize()); in socket.AbstractSocketSessionConfig Seems to work as far as I can tell. Unfortunately I'm neigher familar with the 1.x branch nor with diff but maybe you can create a patch accordingly. The change applied to the default reuse behaviour is required, because the default values are set before anyone is able to override them inside the NioSessionConfig constructor. Edit: Oh, just looked around the sources again: I may be wrong with the default setting. But without changing it, the same app will work on xp/linux but not on vista without setting ReuseAddress explicitly.
        Hide
        Stefano Bagnara added a comment -

        My patch above didn't fix the issue.
        Now I get the same exception on the getKeepAlive:

        2974 [SocketConnector-0] WARN org.apache.mina.common.support.DefaultExceptionMonitor - Unexpected exception.
        org.apache.mina.common.RuntimeIOException: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
        at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:238)
        at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:102)
        at org.apache.mina.transport.socket.nio.SocketConnector.newSession(SocketConnector.java:341)
        at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:295)
        at org.apache.mina.transport.socket.nio.SocketConnector.access$800(SocketConnector.java:53)
        at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:383)
        at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
        at java.lang.Thread.run(Thread.java:619)
        Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
        at sun.nio.ch.Net.getIntOption0(Native Method)
        at sun.nio.ch.Net.getIntOption(Net.java:143)
        at sun.nio.ch.SocketChannelImpl$1.getInt(SocketChannelImpl.java:401)
        at sun.nio.ch.SocketOptsImpl.getBoolean(SocketOptsImpl.java:34)
        at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:88)
        at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268)
        at sun.nio.ch.OptionAdaptor.getKeepAlive(OptionAdaptor.java:147)
        at sun.nio.ch.SocketAdaptor.getKeepAlive(SocketAdaptor.java:326)
        at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:234)
        ... 7 more

        Show
        Stefano Bagnara added a comment - My patch above didn't fix the issue. Now I get the same exception on the getKeepAlive: 2974 [SocketConnector-0] WARN org.apache.mina.common.support.DefaultExceptionMonitor - Unexpected exception. org.apache.mina.common.RuntimeIOException: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:238) at org.apache.mina.transport.socket.nio.SocketSessionImpl.<init>(SocketSessionImpl.java:102) at org.apache.mina.transport.socket.nio.SocketConnector.newSession(SocketConnector.java:341) at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:295) at org.apache.mina.transport.socket.nio.SocketConnector.access$800(SocketConnector.java:53) at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:383) at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) at java.lang.Thread.run(Thread.java:619) Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption at sun.nio.ch.Net.getIntOption0(Native Method) at sun.nio.ch.Net.getIntOption(Net.java:143) at sun.nio.ch.SocketChannelImpl$1.getInt(SocketChannelImpl.java:401) at sun.nio.ch.SocketOptsImpl.getBoolean(SocketOptsImpl.java:34) at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:88) at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268) at sun.nio.ch.OptionAdaptor.getKeepAlive(OptionAdaptor.java:147) at sun.nio.ch.SocketAdaptor.getKeepAlive(SocketAdaptor.java:326) at org.apache.mina.transport.socket.nio.SocketSessionImpl$SessionConfigImpl.setKeepAlive(SocketSessionImpl.java:234) ... 7 more
        Hide
        Stefano Bagnara added a comment -

        I checked out the latest 1.1 branch (1.1.8-SNAPSHOT).
        The first time I ran the tests SocketBindTest failed with the usuale setInt exception.
        Then I've never been able to reproduce that failure in mina tests.

        My application still show the issue so I changed the order of the setReuseAddress and setKeepAlive, but my application still failed. So I also added a check on the keepAlive to call the setter only when the value is really changed and now I don't see the issue anymore.

        Here is the patch I'm using:

        Index: mina-core-1.1/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java
        ===================================================================
        — mina-core-1.1/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java (revision 651305)
        +++ mina-core-1.1/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java (working copy)
        @@ -98,10 +98,10 @@
        IoSessionConfig sessionConfig = serviceConfig.getSessionConfig();
        if (sessionConfig instanceof SocketSessionConfig) {
        SocketSessionConfig cfg = (SocketSessionConfig) sessionConfig;
        + this.config.setReuseAddress(cfg.isReuseAddress());
        this.config.setKeepAlive(cfg.isKeepAlive());
        this.config.setOobInline(cfg.isOobInline());
        this.config.setReceiveBufferSize(cfg.getReceiveBufferSize());

        • this.config.setReuseAddress(cfg.isReuseAddress());
          this.config.setSendBufferSize(cfg.getSendBufferSize());
          this.config.setSoLinger(cfg.getSoLinger());
          this.config.setTcpNoDelay(cfg.isTcpNoDelay());
          @@ -229,7 +229,9 @@

        public void setKeepAlive(boolean on) {
        try {

        • ch.socket().setKeepAlive;
          + if (ch.socket().getKeepAlive() != on) { + ch.socket().setKeepAlive(on); + }

          } catch (SocketException e)

          { throw new RuntimeIOException(e); }

        I'll do more tests as soon as I find the time for them.

        Show
        Stefano Bagnara added a comment - I checked out the latest 1.1 branch (1.1.8-SNAPSHOT). The first time I ran the tests SocketBindTest failed with the usuale setInt exception. Then I've never been able to reproduce that failure in mina tests. My application still show the issue so I changed the order of the setReuseAddress and setKeepAlive, but my application still failed. So I also added a check on the keepAlive to call the setter only when the value is really changed and now I don't see the issue anymore. Here is the patch I'm using: Index: mina-core-1.1/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java =================================================================== — mina-core-1.1/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java (revision 651305) +++ mina-core-1.1/src/main/java/org/apache/mina/transport/socket/nio/SocketSessionImpl.java (working copy) @@ -98,10 +98,10 @@ IoSessionConfig sessionConfig = serviceConfig.getSessionConfig(); if (sessionConfig instanceof SocketSessionConfig) { SocketSessionConfig cfg = (SocketSessionConfig) sessionConfig; + this.config.setReuseAddress(cfg.isReuseAddress()); this.config.setKeepAlive(cfg.isKeepAlive()); this.config.setOobInline(cfg.isOobInline()); this.config.setReceiveBufferSize(cfg.getReceiveBufferSize()); this.config.setReuseAddress(cfg.isReuseAddress()); this.config.setSendBufferSize(cfg.getSendBufferSize()); this.config.setSoLinger(cfg.getSoLinger()); this.config.setTcpNoDelay(cfg.isTcpNoDelay()); @@ -229,7 +229,9 @@ public void setKeepAlive(boolean on) { try { ch.socket().setKeepAlive ; + if (ch.socket().getKeepAlive() != on) { + ch.socket().setKeepAlive(on); + } } catch (SocketException e) { throw new RuntimeIOException(e); } I'll do more tests as soon as I find the time for them.
        Hide
        Daniel Wirtz added a comment - - edited

        Yes, I think this could be the reason. I tried the following now:

        this.connector = new NioSocketConnector(thread_pool, new NioProcessor(thread_pool));
        this.connector.getSessionConfig().setReuseAddress(true);
        etc.

        The exception is still thrown, so maybe the Mina SessionConfigImpl used in org.apache.mina.transport.socket.nio.NioSocketSession internally does not set ReuseAddress before KeepAlive as mentioned in the description you added. Maybe changing the internal order can fix it. I also suggest setting ReuseAddress by default to true, if it is not yet the default behaviour.


        I took a look. The problem is located

        in
        org.apache.mina.transport.socket.AbstractSocketSessionConfig$doSetAll
        called by
        org.apache.mina.common.AbstractIoSessionConfig$setAll
        of course inherited by
        org.apache.mina.transport.socket.nio.NioSocketSession$SocketConfigImpl

        setKeepAlive(cfg.isKeepAlive());
        setOobInline(cfg.isOobInline());
        setReceiveBufferSize(cfg.getReceiveBufferSize());
        setReuseAddress(cfg.isReuseAddress());
        setSendBufferSize(cfg.getSendBufferSize());
        setSoLinger(cfg.getSoLinger());
        setTcpNoDelay(cfg.isTcpNoDelay());

        in conjunction with

        private static boolean DEFAULT_REUSE_ADDRESS = false;

        in
        org.apache.mina.transport.socket.DefaultSocketSessionConfig

        Show
        Daniel Wirtz added a comment - - edited Yes, I think this could be the reason. I tried the following now: this.connector = new NioSocketConnector(thread_pool, new NioProcessor(thread_pool)); this.connector.getSessionConfig().setReuseAddress(true); etc. The exception is still thrown, so maybe the Mina SessionConfigImpl used in org.apache.mina.transport.socket.nio.NioSocketSession internally does not set ReuseAddress before KeepAlive as mentioned in the description you added. Maybe changing the internal order can fix it. I also suggest setting ReuseAddress by default to true, if it is not yet the default behaviour. I took a look. The problem is located in org.apache.mina.transport.socket.AbstractSocketSessionConfig$doSetAll called by org.apache.mina.common.AbstractIoSessionConfig$setAll of course inherited by org.apache.mina.transport.socket.nio.NioSocketSession$SocketConfigImpl setKeepAlive(cfg.isKeepAlive()); setOobInline(cfg.isOobInline()); setReceiveBufferSize(cfg.getReceiveBufferSize()); setReuseAddress(cfg.isReuseAddress()); setSendBufferSize(cfg.getSendBufferSize()); setSoLinger(cfg.getSoLinger()); setTcpNoDelay(cfg.isTcpNoDelay()); in conjunction with private static boolean DEFAULT_REUSE_ADDRESS = false; in org.apache.mina.transport.socket.DefaultSocketSessionConfig
        Hide
        Emmanuel Lecharny added a comment -
        Show
        Emmanuel Lecharny added a comment - May it be connected to this description : ? http://communitygrids.blogspot.com/2007/09/windows-vista-sockets-java-nio-and.html
        Stefano Bagnara made changes -
        Status Resolved [ 5 ] Reopened [ 4 ]
        Resolution Cannot Reproduce [ 5 ]
        Hide
        Stefano Bagnara added a comment -

        Updated to jdk6 update 6 and now I see it more rarely, but after some run I saw the same exception a couple of times.
        I don't know if this could be something wrong I do with mina and threads because I'm not a mina expert, but the same code in XP and linux works.

        Show
        Stefano Bagnara added a comment - Updated to jdk6 update 6 and now I see it more rarely, but after some run I saw the same exception a couple of times. I don't know if this could be something wrong I do with mina and threads because I'm not a mina expert, but the same code in XP and linux works.
        Hide
        Daniel Wirtz added a comment -

        Fully updated Windows Vista, JRE 1.6.0_06 and it is still there:

        org.apache.mina.common.RuntimeIoException: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
        at org.apache.mina.transport.socket.nio.NioSocketSession$SessionConfigImpl.setKeepAlive(NioSocketSession.java:146)
        at org.apache.mina.transport.socket.AbstractSocketSessionConfig.doSetAll(AbstractSocketSessionConfig.java:39)
        at org.apache.mina.common.AbstractIoSessionConfig.setAll(AbstractIoSessionConfig.java:59)
        at org.apache.mina.transport.socket.nio.NioSocketSession.<init>(NioSocketSession.java:77)
        at org.apache.mina.transport.socket.nio.NioSocketConnector.newSession(NioSocketConnector.java:154)
        at org.apache.mina.transport.socket.nio.NioSocketConnector.newSession(NioSocketConnector.java:45)
        at org.apache.mina.common.AbstractPollingIoConnector.processSessions(AbstractPollingIoConnector.java:255)
        at org.apache.mina.common.AbstractPollingIoConnector.access$500(AbstractPollingIoConnector.java:41)
        at org.apache.mina.common.AbstractPollingIoConnector$Worker.run(AbstractPollingIoConnector.java:299)
        at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
        at java.lang.Thread.run(Thread.java:619)
        Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption
        at sun.nio.ch.Net.setIntOption0(Native Method)
        at sun.nio.ch.Net.setIntOption(Net.java:154)
        at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406)
        at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38)
        at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92)
        at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268)
        at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139)
        at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322)
        at org.apache.mina.transport.socket.nio.NioSocketSession$SessionConfigImpl.setKeepAlive(NioSocketSession.java:144)
        ... 12 more

        Show
        Daniel Wirtz added a comment - Fully updated Windows Vista, JRE 1.6.0_06 and it is still there: org.apache.mina.common.RuntimeIoException: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption at org.apache.mina.transport.socket.nio.NioSocketSession$SessionConfigImpl.setKeepAlive(NioSocketSession.java:146) at org.apache.mina.transport.socket.AbstractSocketSessionConfig.doSetAll(AbstractSocketSessionConfig.java:39) at org.apache.mina.common.AbstractIoSessionConfig.setAll(AbstractIoSessionConfig.java:59) at org.apache.mina.transport.socket.nio.NioSocketSession.<init>(NioSocketSession.java:77) at org.apache.mina.transport.socket.nio.NioSocketConnector.newSession(NioSocketConnector.java:154) at org.apache.mina.transport.socket.nio.NioSocketConnector.newSession(NioSocketConnector.java:45) at org.apache.mina.common.AbstractPollingIoConnector.processSessions(AbstractPollingIoConnector.java:255) at org.apache.mina.common.AbstractPollingIoConnector.access$500(AbstractPollingIoConnector.java:41) at org.apache.mina.common.AbstractPollingIoConnector$Worker.run(AbstractPollingIoConnector.java:299) at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907) at java.lang.Thread.run(Thread.java:619) Caused by: java.net.SocketException: Invalid argument: sun.nio.ch.Net.setIntOption at sun.nio.ch.Net.setIntOption0(Native Method) at sun.nio.ch.Net.setIntOption(Net.java:154) at sun.nio.ch.SocketChannelImpl$1.setInt(SocketChannelImpl.java:406) at sun.nio.ch.SocketOptsImpl.setBoolean(SocketOptsImpl.java:38) at sun.nio.ch.SocketOptsImpl.keepAlive(SocketOptsImpl.java:92) at sun.nio.ch.SocketOptsImpl$IP$TCP.keepAlive(SocketOptsImpl.java:268) at sun.nio.ch.OptionAdaptor.setKeepAlive(OptionAdaptor.java:139) at sun.nio.ch.SocketAdaptor.setKeepAlive(SocketAdaptor.java:322) at org.apache.mina.transport.socket.nio.NioSocketSession$SessionConfigImpl.setKeepAlive(NioSocketSession.java:144) ... 12 more
        Hide
        Daniel Wirtz added a comment -

        I can confirm this bug under Windows Vista with JRE 1.6.0 Update 3. As far as I know it is caused by the JRE, not Mina. I'll try upgrading to Update 5 and check if it still exist.

        Show
        Daniel Wirtz added a comment - I can confirm this bug under Windows Vista with JRE 1.6.0 Update 3. As far as I know it is caused by the JRE, not Mina. I'll try upgrading to Update 5 and check if it still exist.
        Trustin Lee made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Cannot Reproduce [ 5 ]
        Assignee Trustin Lee [ trustin ]
        Hide
        Trustin Lee added a comment -

        Can't reproduce in my Windows Vista. Please try to upgrade your JDK. If it still doesn't work with the latest build, please reopen.

        Show
        Trustin Lee added a comment - Can't reproduce in my Windows Vista. Please try to upgrade your JDK. If it still doesn't work with the latest build, please reopen.
        Hide
        Trustin Lee added a comment -

        I don't understand why these two sentences are causing the socket exception. I don't have vista installed yet. Let me test as soon as possible.

        Show
        Trustin Lee added a comment - I don't understand why these two sentences are causing the socket exception. I don't have vista installed yet. Let me test as soon as possible.
        Hide
        Stefano Bagnara added a comment -

        The only similar issue I found on the internet searching for my exception is this: HTTPCORE-29
        Maybe the comments to that issue make sense to some of you even if it is not MINA related it anyway something related to the reactor pattern on nio and setTcpNoDelay call.

        Show
        Stefano Bagnara added a comment - The only similar issue I found on the internet searching for my exception is this: HTTPCORE-29 Maybe the comments to that issue make sense to some of you even if it is not MINA related it anyway something related to the reactor pattern on nio and setTcpNoDelay call.
        Stefano Bagnara created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Stefano Bagnara
          • Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:

              Development