[ 
https://issues.apache.org/jira/browse/DIRMINA-514?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12580872#action_12580872
 ] 

Rob Butler commented on DIRMINA-514:
------------------------------------

I think I've found it.. but I don't know how to fix it.

By walking through the debugger and watching telnet to see when the channel 
actually gets closed I've found it doesn't get closed when you would expect it 
to.

You might expect Channel.close() to immediately close the channel, but it 
doesn't. Instead the channel remains open until the next time 
Selector.select(int) is called. In my older version of Mina 2.0 M1 snapshot the 
SocketIoProcessor$Worker loops again after Channel.close() is called, thus 
calling selector.select(1000) again and closing the channel. In the new Mina 
2.0 M1 snapshot the AbstractPolingIoProcessor$worker immediately checks the 
number of sessions, finds it empty and exits the loop instead of calling 
selector.select(1000). Thus the channel is never closed.

It would appear this isn't a bug in the JVM, as looking at the Javadoc for 
Selector: 
http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/Selector.html it says:

____The cancelled-key set is the set of keys that have been cancelled but whose 
channels have not yet been deregistered.____ This set is not directly 
accessible. The cancelled-key set is always a subset of the key set.

and also says:

A key is added to a selector's key set as a side effect of registering a 
channel via the channel's register method. ____Cancelled keys are removed from 
the key set during selection operations.____

So it would appear that you MUST call selector.select to deregister channels 
(and have them close) before exiting the worker thread loop. I'm sure this will 
be an easy fix for someone more familiar with MINA's internals. This is also 
something that's really easy to overlook, so I would add a unit test to track 
this issue so it doesn't regress.

> Session closing problem on Mac OS X
> -----------------------------------
>
>                 Key: DIRMINA-514
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-514
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.0.0-M1
>         Environment: Mac OS X 10.4 with Java 1.5.0_07 -87
>            Reporter: Matteo Merli
>             Fix For: 2.0.0-M2
>
>         Attachments: Echo1_1.java, Echo2_0.java
>
>
> A call to session.close() does not send a FIN packet althought MINA will 
> considers the session as closed.
> I've attached two test cases, one that works with MINA 1.1 (and works fine) 
> and other with MINA 2.0 that doesn't close connections.
> This is a simple echo server that receives a message, writes it back to the 
> client and (should) close the connection. 
> This problem is *NOT* ocurring on Linux where the same test case works fine. 
> It only shows up on Mac OS X.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to