ADDITIONAL SYSTEM INFORMATION :
Java 11.1, Fedora Linux
A DESCRIPTION OF THE PROBLEM :
If we create a ServerSocketChannel and register for OP_ACCEPT key and then later close it, attempting to open a new ServerSocketChannel on that port fails. This used to work as of Java 1.7_25
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This Junit test shows the issue. It fails on line 31 with a java.net.BindException: Address already in use
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No failure is seen in Java 7
ACTUAL -
It fails on line 31 with a java.net.BindException: Address already in use
---------- BEGIN SOURCE ----------
import org.junit.Test;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
public class ServerChannelBindTest {
@Test
public void testChannelBind() throws Exception {
ServerSocketChannel sc = ServerSocketChannel.open();
sc.configureBlocking(false);
SocketAddress address = new InetSocketAddress(1234);
sc.bind(address);
Selector sel = Selector.open();
sc.register(sel, SelectionKey.OP_ACCEPT);
SocketChannel cc = SocketChannel.open();
cc.connect(address);
sc.close();
sc = ServerSocketChannel.open();
sc.bind(address);
}
}
---------- END SOURCE ----------
FREQUENCY : always
Java 11.1, Fedora Linux
A DESCRIPTION OF THE PROBLEM :
If we create a ServerSocketChannel and register for OP_ACCEPT key and then later close it, attempting to open a new ServerSocketChannel on that port fails. This used to work as of Java 1.7_25
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This Junit test shows the issue. It fails on line 31 with a java.net.BindException: Address already in use
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No failure is seen in Java 7
ACTUAL -
It fails on line 31 with a java.net.BindException: Address already in use
---------- BEGIN SOURCE ----------
import org.junit.Test;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
public class ServerChannelBindTest {
@Test
public void testChannelBind() throws Exception {
ServerSocketChannel sc = ServerSocketChannel.open();
sc.configureBlocking(false);
SocketAddress address = new InetSocketAddress(1234);
sc.bind(address);
Selector sel = Selector.open();
sc.register(sel, SelectionKey.OP_ACCEPT);
SocketChannel cc = SocketChannel.open();
cc.connect(address);
sc.close();
sc = ServerSocketChannel.open();
sc.bind(address);
}
}
---------- END SOURCE ----------
FREQUENCY : always