Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit c6fa82729c0d956a3df8971f37bf6a369b355aee 1 parent e85996e
Trustin Lee trustin authored
17 src/main/java/org/jboss/netty/channel/AbstractChannel.java
@@ -32,7 +32,6 @@
32 32 public abstract class AbstractChannel implements Channel {
33 33
34 34 static final ConcurrentMap<Integer, Channel> allChannels = new ConcurrentHashMap<Integer, Channel>();
35   - private static final IdDeallocator ID_DEALLOCATOR = new IdDeallocator();
36 35
37 36 private static Integer allocateId(Channel channel) {
38 37 Integer id = Integer.valueOf(System.identityHashCode(channel));
@@ -49,17 +48,6 @@ private static Integer allocateId(Channel channel) {
49 48 }
50 49 }
51 50
52   - private static final class IdDeallocator implements ChannelFutureListener {
53   - IdDeallocator() {
54   - super();
55   - }
56   -
57   - @Override
58   - public void operationComplete(ChannelFuture future) throws Exception {
59   - allChannels.remove(future.getChannel().getId());
60   - }
61   - }
62   -
63 51 private final Integer id;
64 52 private final Channel parent;
65 53 private final ChannelFactory factory;
@@ -94,7 +82,6 @@ protected AbstractChannel(
94 82 this.pipeline = pipeline;
95 83
96 84 id = allocateId(this);
97   - closeFuture.addListener(ID_DEALLOCATOR);
98 85
99 86 pipeline.attach(this, sink);
100 87 }
@@ -200,6 +187,10 @@ public boolean isOpen() {
200 187 * closed yet
201 188 */
202 189 protected boolean setClosed() {
  190 + // Deallocate the current channel's ID from allChannels so that other
  191 + // new channels can use it.
  192 + allChannels.remove(id);
  193 +
203 194 return closeFuture.setClosed();
204 195 }
205 196
10 src/main/java/org/jboss/netty/channel/socket/nio/NioSocketChannel.java
@@ -83,15 +83,6 @@ public NioSocketChannel(
83 83 this.socket = socket;
84 84 this.worker = worker;
85 85 config = new DefaultNioSocketChannelConfig(socket.socket());
86   -
87   - // TODO Move the state variable to AbstractChannel so that we don't need
88   - // to add many listeners.
89   - getCloseFuture().addListener(new ChannelFutureListener() {
90   - @Override
91   - public void operationComplete(ChannelFuture future) throws Exception {
92   - state = ST_CLOSED;
93   - }
94   - });
95 86 }
96 87
97 88 @Override
@@ -157,6 +148,7 @@ final void setConnected() {
157 148
158 149 @Override
159 150 protected boolean setClosed() {
  151 + state = ST_CLOSED;
160 152 return super.setClosed();
161 153 }
162 154

0 comments on commit c6fa827

Please sign in to comment.
Something went wrong with that request. Please try again.