[ https://issues.apache.org/jira/browse/DIRMINA-1014?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Nipun updated DIRMINA-1014: --------------------------- Description: When the AbstractIoAcceptor binds a socket, it adds an entry to the "boundAddresses" set to keep track of that socket. In my case, I am passing a SocketAddress initialized with a specific port, and "null" for host (I want to listen on that port on the local machine). This InetSocketAddress instance has an Inet4Address in it when created. When the Acceptor is given this v4 SocketAddress to bind, it creates a ServerSocketChannel, and then calls ServerSocketChannel.socket().getLocalSocketAddress() to retrieve a SocketAddress. This is the value that is then put in the "boundAddresses" collection. The problem is that the ServerSocketChannel.socket().getLocalSocketAddress() returns a SocketAddress with an Inet6Address value in it, even though the SocketAcceptor.bind() was given a v4 address. So when I try to unbind that socket (using the same v4 address I used to do the bind() call), it fails because the "boundAddresses" set has the v6 version in it, and the "Inet6Address.equals(Inet4Address) is false". Basically: 1. I call NioSocketAcceptor.bind() on a v4 SocketAddress 2. A ServerSocketChannel is created for that v4 address. 3. The ServerSocketChannel.socket().getLocalSocketAddress() is called, which returns a v6 SocketAddress (which is the equivalent of the v4 SocketAddress given) 4. NioSocketAcceptor puts the v6 address in its "boundAddresses" list. 5. When I ask to unbind the same v4 address, it fails because the "boundAddresses" list only contains a v6 address. Suggested Fix: 1. Make the "boundAddresses" field a Map<SocketAddress,SocketAddress>. The keys should be the SocketAddress parameter passed to the bind() call, the values should be the ServerSocketChannel.socket().getLocalSocketAddress(). 2. When unbind(a) is called, check "boundAddresses.hasKey(a)", and if true, then unbind "boundAddresses.get(a)". This makes it consistent for the client; they can use the same instance of SocketAddress to bind and unbind reliably. This will match Mina v1.x version, where the SocketAddress passed to the bind() method could be used to also unbind. was: When the AbstractIoAcceptor binds a socket, it adds an entry to the "boundAddresses" set to keep track of that socket. In my case, I am passing a SocketAddress initialized with a specific port, and "null" for host (I want to listen on that port on the local machine). This InetSocketAddress instance has an Inet4Address in it when created. When the Acceptor is given this v4 SocketAddress to bind, it creates a ServerSocketChannel, and then calls ServerSocketChannel.socket().getLocalSocketAddress() to retrieve a SocketAddress. This is the value that is then put in the "boundAddresses" collection. The problem is that the ServerSocketChannel.socket().getLocalSocketAddress() returns a SocketAddress with an Inet6Address value in it, even though the SocketAcceptor.bind() was given a v4 address. So when I try to unbind that socket (using the same v4 address I used to do the bind() call), it fails because the "boundAddresses" set has the v6 version in it, and the "Inet6Address.equals(Inet4Address) is false". Basically: 1. I call NioSocketAcceptor.bind() on a v4 SocketAddress 2. A ServerSocketChannel is created for that v4 address. 3. The ServerSocketChannel.socket().getLocalSocketAddress() is called, which returns a v6 SocketAddress (which is the equivalent of the v4 SocketAddress given) 4. NioSocketAcceptor puts the v6 address in its "boundAddresses" list. 5. When I ask to unbind the same v4 address, it fails because the "boundAddresses" list only contains a v6 address. Suggested Fix: 1. Make the "boundAddresses" field a Map<SocketAddress,SocketAddress>. The keys should be the SocketAddress parameter passed to the bind() call, the values should be the ServerSocketChannel.socket().getLocalSocketAddress(). 2. When unbind(x) is called, check "boundAddresses.hasKey(x)", and if true, then unbind "boundAddresses.get(x)". This makes it consistent for the client; they can use the same instance of SocketAddress to bind and unbind reliably. This will match Mina v1.x version, where the SocketAddress passed to the bind() method could be used to also unbind. > SocketAcceptor doesn't unbind correctly > --------------------------------------- > > Key: DIRMINA-1014 > URL: https://issues.apache.org/jira/browse/DIRMINA-1014 > Project: MINA > Issue Type: Bug > Components: Core > Affects Versions: 2.0.9 > Environment: Ubuntu 12.04.5 x64 > Oracle JDK 1.6.0_45 > Mina 2.0.9 > Reporter: Nipun > > When the AbstractIoAcceptor binds a socket, it adds an entry to the > "boundAddresses" set to keep track of that socket. > In my case, I am passing a SocketAddress initialized with a specific port, > and "null" for host (I want to listen on that port on the local machine). > This InetSocketAddress instance has an Inet4Address in it when created. > When the Acceptor is given this v4 SocketAddress to bind, it creates a > ServerSocketChannel, and then calls > ServerSocketChannel.socket().getLocalSocketAddress() to retrieve a > SocketAddress. This is the value that is then put in the "boundAddresses" > collection. > The problem is that the ServerSocketChannel.socket().getLocalSocketAddress() > returns a SocketAddress with an Inet6Address value in it, even though the > SocketAcceptor.bind() was given a v4 address. So when I try to unbind that > socket (using the same v4 address I used to do the bind() call), it fails > because the "boundAddresses" set has the v6 version in it, and the > "Inet6Address.equals(Inet4Address) is false". > Basically: > 1. I call NioSocketAcceptor.bind() on a v4 SocketAddress > 2. A ServerSocketChannel is created for that v4 address. > 3. The ServerSocketChannel.socket().getLocalSocketAddress() is called, which > returns a v6 SocketAddress (which is the equivalent of the v4 SocketAddress > given) > 4. NioSocketAcceptor puts the v6 address in its "boundAddresses" list. > 5. When I ask to unbind the same v4 address, it fails because the > "boundAddresses" list only contains a v6 address. > Suggested Fix: > 1. Make the "boundAddresses" field a Map<SocketAddress,SocketAddress>. The > keys should be the SocketAddress parameter passed to the bind() call, the > values should be the ServerSocketChannel.socket().getLocalSocketAddress(). > 2. When unbind(a) is called, check "boundAddresses.hasKey(a)", and if true, > then unbind "boundAddresses.get(a)". > This makes it consistent for the client; they can use the same instance of > SocketAddress to bind and unbind reliably. > This will match Mina v1.x version, where the SocketAddress passed to the > bind() method could be used to also unbind. -- This message was sent by Atlassian JIRA (v6.3.4#6332)