[
https://issues.apache.org/jira/browse/DIRMINA-869?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Julien Vermillard resolved DIRMINA-869.
---------------------------------------
Resolution: Fixed
Assignee: Julien Vermillard
> 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
> Affects Versions: 3.0.0-trunk
> Reporter: Martin Ellis
> Assignee: Julien Vermillard
> Fix For: 3.0.0-M1
>
>
> 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:
> private Set<SocketAddress> addresses =
> Collections.synchronizedSet(new HashSet<SocketAddress>());
> ...
> public void unbindAll() throws IOException {
> for (SocketAddress socketAddress : addresses) {
> unbind(socketAddress);
> }
> }
> From the unsynchronizedSet javadoc.
> 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());
> }
> 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
For more information on JIRA, see: http://www.atlassian.com/software/jira