Details
Description
NOTE: This issue occurs with 2.0.0 and 2.0.1
Comment out the addListener and apparent Deadlock goes away.
final IoServiceListener listener = new UdpIoServiceListener();
// APACHE: THIS CREATES A DEADLOCK
acceptor.addListener(listener);
When the listener is added bind never returns.
acceptor.bind(new InetSocketAddress(12345));
If you comment out the addListener, bind returns and you will see
the System.out..
(Compilable code inlined showing issue)
[BEGIN]
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Set;
import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.service.IoService;
import org.apache.mina.core.service.IoServiceListener;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.logging.LoggingFilter;
import org.apache.mina.transport.socket.DatagramSessionConfig;
import org.apache.mina.transport.socket.nio.NioDatagramAcceptor;
public class UdpBug {
public static class UdpIoServiceListener implements IoServiceListener {
@Override
public void serviceActivated(final IoService service) throws Exception
@Override
public void serviceDeactivated(final IoService service) throws Exception
@Override
public void serviceIdle(final IoService service, final IdleStatus status) throws Exception
@Override
public void sessionCreated(final IoSession session) throws Exception
@Override
public void sessionDestroyed(final IoSession session) throws Exception
}
public static class UdpIoHandler extends IoHandlerAdapter {
public UdpIoHandler() {
}
@Override
public void sessionCreated(final IoSession session) throws Exception
@Override
public void sessionOpened(final IoSession session) throws Exception
@Override
public void sessionClosed(final IoSession session) throws Exception
@Override
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception
@Override
public void exceptionCaught(final IoSession session, final Throwable cause) throws Exception
@Override
public void messageReceived(final IoSession session, final Object message) throws Exception
}
public static final void main(String[] args) throws IOException {
// ByteBuffer.setUseDirectBuffers(false);
NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
acceptor.setCloseOnDeactivation(true);
final IoServiceListener listener = new UdpIoServiceListener();
// APACHE: THIS CREATES A DEADLOCK
acceptor.addListener(listener);
final DatagramSessionConfig sessionConfig = acceptor.getSessionConfig();
sessionConfig.setReuseAddress(true);
final DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
final LoggingFilter loggingFilter = new LoggingFilter();
chain.addLast("logFilter", loggingFilter);
// acceptor.setFilterChainBuilder(chain);
acceptor.setHandler(new UdpIoHandler());
acceptor.bind(new InetSocketAddress(12345));
final Set<SocketAddress> addrs = acceptor.getLocalAddresses();
for (final SocketAddress addr : addrs)
System.out.println("UdpServer started on port " + 12345);
}
}
[END]