mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kenji Hollis (JIRA)" <j...@apache.org>
Subject [jira] Issue Comment Edited: (DIRMINA-386) SocketSessionConfigImpl: initialize() uses "localhost" to bind InetSocketAddress, should use IP instead
Date Fri, 08 Jun 2007 21:37:26 GMT

    [ https://issues.apache.org/jira/browse/DIRMINA-386?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12502942
] 

Kenji Hollis edited comment on DIRMINA-386 at 6/8/07 2:36 PM:
--------------------------------------------------------------

Well, there's no patch, but further research fixes the issue without having to require a ServerSocket
to get the information.  The JDK 6 does not state that the socket be connected to any active
servers when retrieving the socket options.  Further research indicates that this is true
with the SocketOptions class.  As a result, I was able to remove the ServerSocket and connect
class calls, and this returned the same results that the server wanted.

This block of code seems to fix the issue, and does not make the test cases (as of 1.1.1)
fail.  This fixes the test cases in my code, and it seems to do the trick!  Here is the code:

-- Snip --
    private static void initialize()
    {
        Socket socket = null;

        try {
            socket = new Socket();

            DEFAULT_REUSE_ADDRESS = socket.getReuseAddress();
            DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize();
            DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize();
            DEFAULT_KEEP_ALIVE = socket.getKeepAlive();
            DEFAULT_OOB_INLINE = socket.getOOBInline();
            DEFAULT_SO_LINGER = socket.getSoLinger();
            DEFAULT_TCP_NO_DELAY = socket.getTcpNoDelay();

            // Check if setReceiveBufferSize is supported.
            try
            {
                socket.setReceiveBufferSize(DEFAULT_RECEIVE_BUFFER_SIZE);
                SET_RECEIVE_BUFFER_SIZE_AVAILABLE = true;
            }
            catch( SocketException e )
            {
                SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false;
            }

            // Check if setSendBufferSize is supported.
            try
            {
                socket.setSendBufferSize(DEFAULT_SEND_BUFFER_SIZE);
                SET_SEND_BUFFER_SIZE_AVAILABLE = true;
            }
            catch( SocketException e )
            {
                SET_SEND_BUFFER_SIZE_AVAILABLE = false;
            }

            // Check if getTrafficClass is supported.
            try
            {
                DEFAULT_TRAFFIC_CLASS = socket.getTrafficClass();
                GET_TRAFFIC_CLASS_AVAILABLE = true;
            }
            catch( SocketException e )
            {
                GET_TRAFFIC_CLASS_AVAILABLE = false;
                DEFAULT_TRAFFIC_CLASS = 0;
            }
        }
        catch( Exception e )
        {
            throw new ExceptionInInitializerError(e);
        }
    }
-- Snip --

Major changes:
- Note that the try/catch no longer has a finally block.
- Note the absence of the <code>ServerSocket</code>

If someone else can verify these changes work with their code, this would be perfect.  If
this works, I would suggest that it be added to the current code base - I can't be the only
one with this issue!  After adding this fix, my test code works.  Not only does it work, but
works without any noticeable changes in behavior - if any exist.

I have not tested this on Windows.  Solaris tests pass as well.


 was:
Well, there's no patch, but further research fixes the issue without having to require a ServerSocket
to get the information.  The JDK 6 does not state that the socket be connected to any active
servers when retrieving the socket options.  Further research indicates that this is true
with the SocketOptions class.  As a result, I was able to remove the ServerSocket and connect
class calls, and this returned the same results that the server wanted.

This block of code seems to fix the issue, and does not make the test cases (as of 1.1.1)
fail.  This fixes the test cases in my code, and it seems to do the trick!  Here is the code:

-- Snip --
<pre>
    private static void initialize()
    {
        Socket socket = null;

        try {
            socket = new Socket();

            DEFAULT_REUSE_ADDRESS = socket.getReuseAddress();
            DEFAULT_RECEIVE_BUFFER_SIZE = socket.getReceiveBufferSize();
            DEFAULT_SEND_BUFFER_SIZE = socket.getSendBufferSize();
            DEFAULT_KEEP_ALIVE = socket.getKeepAlive();
            DEFAULT_OOB_INLINE = socket.getOOBInline();
            DEFAULT_SO_LINGER = socket.getSoLinger();
            DEFAULT_TCP_NO_DELAY = socket.getTcpNoDelay();

            // Check if setReceiveBufferSize is supported.
            try
            {
                socket.setReceiveBufferSize(DEFAULT_RECEIVE_BUFFER_SIZE);
                SET_RECEIVE_BUFFER_SIZE_AVAILABLE = true;
            }
            catch( SocketException e )
            {
                SET_RECEIVE_BUFFER_SIZE_AVAILABLE = false;
            }

            // Check if setSendBufferSize is supported.
            try
            {
                socket.setSendBufferSize(DEFAULT_SEND_BUFFER_SIZE);
                SET_SEND_BUFFER_SIZE_AVAILABLE = true;
            }
            catch( SocketException e )
            {
                SET_SEND_BUFFER_SIZE_AVAILABLE = false;
            }

            // Check if getTrafficClass is supported.
            try
            {
                DEFAULT_TRAFFIC_CLASS = socket.getTrafficClass();
                GET_TRAFFIC_CLASS_AVAILABLE = true;
            }
            catch( SocketException e )
            {
                GET_TRAFFIC_CLASS_AVAILABLE = false;
                DEFAULT_TRAFFIC_CLASS = 0;
            }
        }
        catch( Exception e )
        {
            throw new ExceptionInInitializerError(e);
        }
    }
</pre>
-- Snip --

Major changes:
<li> Note that the try/catch no longer has a finally block.
<li> Note the absence of the <code>ServerSocket</code>

If someone else can verify these changes work with their code, this would be perfect.  If
this works, I would suggest that it be added to the current code base - I can't be the only
one with this issue!  After adding this fix, my test code works.  Not only does it work, but
works without any noticeable changes in behavior - if any exist.

I have not tested this on Windows.  Solaris tests pass as well.

> SocketSessionConfigImpl: initialize() uses "localhost" to bind InetSocketAddress, should
use IP instead
> -------------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-386
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-386
>             Project: MINA
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 1.1.0, 1.1.1, 2.0.0-M1
>         Environment: JDK 5/6, Linux, Windows, Solaris
>            Reporter: Kenji Hollis
>             Fix For: 1.1.1
>
>
> The main issue here is if a programmer has decided to override the DNS entries, or run
the MINA software in a firewalled environment (where DNS is firewalled, for instance), MINA
will throw an "Unresolved Host" IO Exception at line 66 of SocketSessionConfigImpl.java. 
This can flat-out be re-created every time by simply overriding the DNS entry on the local
machine to 127.0.0.1 (resolv.conf).
> Because the "initialize()" function simply binds to localhost to retrieve socket configuration
defaults, there is a better way to approach this.  This method has been tested, and is known
to work.
> Instead of binding to localhost, bind to "127.0.0.1" or "0.0.0.0" as the address.  Binding
to 127.0.0.1 will do the exact same thing, effectively, as looking up localhost.  Ultimately,
this will be a FASTER initialization, as it needs to resolve "localhost" to an IP.  By giving
the system an IP address to begin with, we resolve this issue.
> What I did was created a local private static final String called "LOCALHOST_ADDRESS"
in the top area of the class, and set it to 127.0.0.1.  I then modified line 66 to use LOCALHOST_ADDRESS,
as well as line 73 to use LOCALHOST_ADDRESS on the socket.connect.
> At the company I work for, we were able to recreate the issue of the code NOT working,
and the code WORKING.  By modifying the code to use localhost as 127.0.0.1 or 0.0.0.0, we
got around the DNS lookup failure, and MINA fired right up happily.
> I recommend this fix be added in the next release - both major and minor - for MINA.
 The company I work for is doing performance testing with MINA now, and we may be using it
to replace the main socket functionality if all goes well.  I would like to see this fix in
the next milestone release if at all possible.
> If you need a patch file provided, I would be more than happy to give one!

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message