I have a client application using Mina that repeatedly tries to connect (every 30 seconds or so) to a server. If the server is not running, I get what I would expect:

[...]
Caused by: java.io.IOException: Failed to get the session.
at org.apache.mina.common.ConnectFuture.getSession(ConnectFuture.java:73) at com.citi.lws.bindings.tcpip.TcpIpClientBinding.connect(TcpIpClientBinding.java:137)
       ... 48 more
Caused by: java.net.ConnectException: Connection refused: no further information
       at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:527) at org.apache.mina.transport.socket.nio.SocketConnector.processSessions(SocketConnector.java:285) at org.apache.mina.transport.socket.nio.SocketConnector.access$800(SocketConnector.java:48) at org.apache.mina.transport.socket.nio.SocketConnector$Worker.run(SocketConnector.java:388)


However, after a few attempts the connection seems to succeed and my IoHandler's sessionOpened event fires. The session.getRemoteAddress() == null and session.isConnected() == true.

Since my application now thinks there is a connection to some non-existent server, it then attempts to send data through the link, and I see this in my logs:

[WARN ][support.DefaultExceptionMonitor] Unexpected exception.
java.nio.channels.NotYetConnectedException
at sun.nio.ch.SocketChannelImpl.ensureWriteOpen(SocketChannelImpl.java:129)
       at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:294)
at org.apache.mina.transport.socket.nio.SocketIoProcessor.doFlush(SocketIoProcessor.java:480) at org.apache.mina.transport.socket.nio.SocketIoProcessor.doFlush(SocketIoProcessor.java:412) at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$500(SocketIoProcessor.java:41) at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:568)

Is this a bug or is my client doing something it shouldn't be doing? The connect code is just:

ConnectFuture connectFuture = ioConnector.connect(socketAddress, ioHandler);
       connectFuture.join();
       ioSession = connectFuture.getSession();

Thanks,
Raman

Reply via email to