Hello,
I have finally found where the problem was. It was in my code:
I called ConnectionRequest.cancel() for a connection request in the
"done" state. Now I added the check:
if (!connectionRequest.isDone()) {
connectionRequest.cancel();
}
I think it would be great to add this check to ConnectionRequest class
itself. Otherwise mina adds the request to cancelQueue, but in fact
there is nothing to cancel - that's why the Connector's run() loop works
incorrectly.
What do you think?
Thanks,
Victor
Victor wrote:
Just a question:
why does Connector.run() thread exit when nHandles==0? Why not to
continue executing select() in the loop infinitely?
Thanks,
Victor
Victor wrote:
Unfortunately, even with the patch in Connector and Processor, the
problem is reproduced randomly, most of time everything works, but
sometimes I see that sessionCreated is not called. But if I start a
new connection, this "old" pending connection (for which I am waiting
for sessionCreated callback) is completed instantly, so I get
sessionCreated.
Victor N
Victor wrote:
I have added a similar fix in
AbstractPollingIoProcessor.Processor.run() - nSessions is now
initialized inside the loop, on each iteration.
It seems to work now, I can not reproduce the bug, but I will
continue testing.
Not sure whether this patch is adequate or nor. Any comments?
Victor N
Victor wrote:
I tried to play with my fix - from the first glance, it seemed to
work - connection was established, sessionCreated was called,
but at the second attempt the problem reproduced.
Any ideas what is wrong here?
Thanks,
Victor N
Victor wrote:
Hello,
I have a problem with NIO connector in mina 2.0 M4 when handling
many simultaneous connections - sometimes after calling connect() I
do not receive sessionCreated() callback.
I am trying to prepare a small test, but I can not reproduce the
problem in this test yet, so I tried to investigate mina sources
myself using out working system.
I can see that a new Channel is always created, channel.connect()
is called, SYN, SYN-ACK, ACK are sent, then I see that
AbstractPollingIoConnector.Connector registers the new channel in
Selector, but after that AbstractPollingIoConnector.Connector is
stopped because nHandles=0 and connectQueue is already empty (no
more connection requests).
I mean the following code in
AbstractPollingIoConnector.Connector.run():
if (nHandles == 0) {
synchronized (lock) {
if (connectQueue.isEmpty()) {
connector = null;
break;
}
}
}
After that, 'select' is not called on the Selector anymore for this
session.
One reason of this behavior (which I can assume now) is 'nHandles'
variable initialized outside of 'while' loop. Maybe, it should be
initialized on each iteration? So every time we calculate the
number of new sessions, canceled sessions, etc.
In my situation, nHandles=-1, then, after registering the new
session, nHandles becomes 0 and the Connector.run() is stopped.
Victor N