NETTY-417 client channel still open after close and wait

* Fixed a race condition where NioSocketChannel's state variable is updated *after* its close future is notified
* Removed unnecessary use of ChannelFutureListeners in NioSocketChannel and AbstractChannel

Conflicts:

	src/main/java/org/jboss/netty/channel/AbstractChannel.java
	src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java
This commit is contained in:
Trustin Lee 2011-08-02 07:38:16 +09:00
parent caf8b39172
commit 07e9378423
2 changed files with 5 additions and 20 deletions

View File

@ -32,7 +32,6 @@ import org.jboss.netty.util.internal.ConcurrentHashMap;
public abstract class AbstractChannel implements Channel {
static final ConcurrentMap<Integer, Channel> allChannels = new ConcurrentHashMap<Integer, Channel>();
private static final IdDeallocator ID_DEALLOCATOR = new IdDeallocator();
private static Integer allocateId(Channel channel) {
Integer id = Integer.valueOf(System.identityHashCode(channel));
@ -49,16 +48,6 @@ public abstract class AbstractChannel implements Channel {
}
}
private static final class IdDeallocator implements ChannelFutureListener {
IdDeallocator() {
super();
}
public void operationComplete(ChannelFuture future) throws Exception {
allChannels.remove(future.getChannel().getId());
}
}
private final Integer id;
private final Channel parent;
private final ChannelFactory factory;
@ -93,7 +82,6 @@ public abstract class AbstractChannel implements Channel {
this.pipeline = pipeline;
id = allocateId(this);
closeFuture.addListener(ID_DEALLOCATOR);
pipeline.attach(this, sink);
}
@ -193,6 +181,10 @@ public abstract class AbstractChannel implements Channel {
* closed yet
*/
protected boolean setClosed() {
// Deallocate the current channel's ID from allChannels so that other
// new channels can use it.
allChannels.remove(id);
return closeFuture.setClosed();
}

View File

@ -83,14 +83,6 @@ class NioSocketChannel extends AbstractChannel
this.socket = socket;
this.worker = worker;
config = new DefaultNioSocketChannelConfig(socket.socket());
// TODO Move the state variable to AbstractChannel so that we don't need
// to add many listeners.
getCloseFuture().addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
state = ST_CLOSED;
}
});
}
public NioSocketChannelConfig getConfig() {
@ -151,6 +143,7 @@ class NioSocketChannel extends AbstractChannel
@Override
protected boolean setClosed() {
state = ST_CLOSED;
return super.setClosed();
}