Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
3.0.0-DEAD
-
None
Description
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)
}
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)
Another fix might be to use a set from java.util.concurrent.