Hello,

I have TCP server which during creation of session checks the number of 
accepted connections. And if that number is reached then server closes incoming 
connection.
But while server preparing to close and actully close session, client able to 
send data to that session. After that data will be lost on server side.
Before writing to session, client checks (session.isConnected() && 
!session.isClosing()) and it is true.

It is not 100% reproducible. Process of open/write/close takes less then 1 
second, but as a result data is lost. It is too fast process.

What can you suggest to avoid such situations? 
How to check if session is really opened and ready to transmit data?
Maybe add some timeouts?

MINA 1.1.7 used


Here are extracted part of traces if it can help 
port 9234 - server
port 2400 - client

18:27:38,882 | INFO  | SocketConnectorIoProcessor-5.0 | Session CREATED: 
(SOCKET, R: /127.0.0.1:9234, L: /127.0.0.1:2400, S: /127.0.0.1:9234)
18:27:38,898 | INFO  | AnonymousIoService-3 | Session OPENED: (SOCKET, R: 
/127.0.0.1:9234, L: /127.0.0.1:2400, S: /127.0.0.1:9234)
18:27:38,913 | INFO  | SocketAcceptorIoProcessor-0.0 | Session CREATED: 
(SOCKET, R: /127.0.0.1:2400, L: /127.0.0.1:9234, S: /127.0.0.1:9234)
--> here server check number of connections
18:27:38,913 | DEBUG | SocketAcceptorIoProcessor-0.0 | Accepting connection 
number: 2, Session: (SOCKET, R: /127.0.0.1:2400, L: /127.0.0.1:9234, S: 
/127.0.0.1:9234)
--> and closes that one
18:27:38,929 | WARN  | SocketAcceptorIoProcessor-0.0 | Connection number 
reached: 2, close connection (SOCKET, R: /127.0.0.1:2400, L: /127.0.0.1:9234, 
S: /127.0.0.1:9234)
--> but client still write data
18:27:38,913 | INFO  | main       | TCPClient WRITE: DirectBuffer[pos=0 lim=2 
cap=1024: 0B 4D]
18:27:38,929 | INFO  | main       | TCPClient WRITE: HeapBuffer[pos=0 lim=0 
cap=0: empty]
18:27:38,929 | INFO  | SocketAcceptorIoProcessor-0.0 | TCPServer CLOSE
18:27:38,929 | INFO  | TCPClient SENT: DirectBuffer[pos=0 lim=2 cap=1024: 0B 4D]
--> only here server opened session, however it is already in closing stage
18:27:38,960 | INFO  | Session OPENED: (SOCKET, R: /127.0.0.1:2400, L: 
/127.0.0.1:9234, S: /127.0.0.1:9234) 
18:27:38,945 | INFO  | TCPClient SENT: HeapBuffer[pos=0 lim=0 cap=0: empty]
18:27:38,976 | INFO  | Session CLOSED: (SOCKET, R: /127.0.0.1:9234, L: 
/127.0.0.1:2400, S: /127.0.0.1:9234)
18:27:38,976 | INFO  | Session CLOSED: (SOCKET, R: /127.0.0.1:2400, L: 
/127.0.0.1:9234, S: /127.0.0.1:9234)


Sergiy Mamit'ko

Reply via email to