[
https://issues.apache.org/jira/browse/DIRMINA-869?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13143264#comment-13143264
]
Emmanuel Lecharny commented on DIRMINA-869:
-------------------------------------------
Hmmm, good catch !
I will see if I can fix the code asap.
Thanks for the report !
> NioTcpServer is not thread-safe when unbinding sockets
> ------------------------------------------------------
>
> Key: DIRMINA-869
> URL: https://issues.apache.org/jira/browse/DIRMINA-869
> Project: MINA
> Issue Type: Bug
> Components: Core
> Reporter: Martin Ellis
>
> The addresses field is a HashSet wrapped using Collections.synchronizedSet.
> The modifications to the set in the bind(...) and unbind(...) method, are
> guarded by synchronizing on 'this'.
> However, the unbindAll() method iterates over the set, without
> synchronization. This could lead to a bug if a call to unbindAll() is made
> while a socket is being bind()'ed or unbind()'ed.
> From NioTcpServer:
> {noformat}
> private Set<SocketAddress> addresses =
> Collections.synchronizedSet(new HashSet<SocketAddress>());
> ...
> public void unbindAll() throws IOException {
> for (SocketAddress socketAddress : addresses) {
> unbind(socketAddress);
> }
> }
> {noformat}
> From the unsynchronizedSet javadoc.
> {noformat}
> It is imperative that the user manually synchronize on the returned set when
> iterating over it:
> Set s = Collections.synchronizedSet(new HashSet());
> ...
> synchronized(s) {
> Iterator i = s.iterator(); // Must be in the synchronized block
> while (i.hasNext())
> foo(i.next());
> }
> {noformat}
> Another fix might be to use a set from java.util.concurrent.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira