Skip to content

Commit 91d12f5

Browse files
authored
Merge pull request #679 from jooby-project/677
netty: random java.nio.channels.ClosedChannelException: null while cl…
2 parents d7eca9d + a272bfc commit 91d12f5

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

jooby-netty/src/main/java/org/jooby/internal/netty/NettyWebSocket.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
package org.jooby.internal.netty;
2020

21-
import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE;
21+
import static io.netty.channel.ChannelFutureListener.CLOSE;
2222
import static java.util.Objects.requireNonNull;
2323

2424
import java.io.IOException;
@@ -50,8 +50,8 @@
5050

5151
public class NettyWebSocket implements NativeWebSocket {
5252

53-
public static final AttributeKey<NettyWebSocket> KEY =
54-
AttributeKey.newInstance(NettyWebSocket.class.getName());
53+
public static final AttributeKey<NettyWebSocket> KEY = AttributeKey
54+
.newInstance(NettyWebSocket.class.getName());
5555

5656
/** The logging system. */
5757
private final Logger log = LoggerFactory.getLogger(getClass());
@@ -84,7 +84,7 @@ public NettyWebSocket(final ChannelHandlerContext ctx,
8484
@Override
8585
public void close(final int status, final String reason) {
8686
handshaker.close(ctx.channel(), new CloseWebSocketFrame(status, reason))
87-
.addListener(FIRE_EXCEPTION_ON_FAILURE);
87+
.addListener(CLOSE);
8888
Attribute<NettyWebSocket> ws = ctx.channel().attr(KEY);
8989
if (ws != null) {
9090
ws.set(null);
@@ -135,7 +135,7 @@ public void pause() {
135135
@Override
136136
public void terminate() throws IOException {
137137
this.onCloseCallback.accept(1006, Optional.of("Harsh disconnect"));
138-
ctx.disconnect().addListener(FIRE_EXCEPTION_ON_FAILURE);
138+
ctx.disconnect().addListener(CLOSE);
139139
}
140140

141141
@Override
@@ -193,7 +193,7 @@ public void handle(final Object msg) {
193193
int statusCode = closeFrame.statusCode();
194194
onCloseCallback.accept(statusCode == -1 ? WebSocket.NORMAL.code() : statusCode,
195195
Optional.ofNullable(closeFrame.reasonText()));
196-
handshaker.close(ctx.channel(), closeFrame).addListener(FIRE_EXCEPTION_ON_FAILURE);
196+
handshaker.close(ctx.channel(), closeFrame).addListener(CLOSE);
197197
} else if (msg instanceof Throwable) {
198198
onErrorCallback.accept((Throwable) msg);
199199
}

jooby-netty/src/test/java/org/jooby/internal/netty/NettyWebSocketTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.jooby.internal.netty;
22

3-
import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE;
3+
import static io.netty.channel.ChannelFutureListener.CLOSE;
44
import static org.easymock.EasyMock.expect;
55
import static org.easymock.EasyMock.expectLastCall;
66
import static org.easymock.EasyMock.isA;
@@ -57,7 +57,7 @@ public class NettyWebSocketTest {
5757
1001, "normal");
5858

5959
ChannelFuture future = unit.mock(ChannelFuture.class);
60-
expect(future.addListener(FIRE_EXCEPTION_ON_FAILURE)).andReturn(future);
60+
expect(future.addListener(CLOSE)).andReturn(future);
6161

6262
WebSocketServerHandshaker handshaker = unit.get(WebSocketServerHandshaker.class);
6363
expect(handshaker.close(ch, frame)).andReturn(future);
@@ -202,7 +202,7 @@ public void terminate() throws Exception {
202202
callback.accept(1006, Optional.of("Harsh disconnect"));
203203

204204
ChannelFuture future = unit.mock(ChannelFuture.class);
205-
expect(future.addListener(FIRE_EXCEPTION_ON_FAILURE)).andReturn(future);
205+
expect(future.addListener(CLOSE)).andReturn(future);
206206

207207
ChannelHandlerContext ctx = unit.get(ChannelHandlerContext.class);
208208
expect(ctx.disconnect()).andReturn(future);
@@ -584,7 +584,7 @@ public void handleCloseFrame() throws Exception {
584584
expect(ctx.channel()).andReturn(ch);
585585

586586
ChannelFuture future = unit.mock(ChannelFuture.class);
587-
expect(future.addListener(FIRE_EXCEPTION_ON_FAILURE)).andReturn(future);
587+
expect(future.addListener(CLOSE)).andReturn(future);
588588

589589
WebSocketServerHandshaker handshaker = unit.get(WebSocketServerHandshaker.class);
590590
expect(handshaker.close(ch, retain)).andReturn(future);
@@ -625,7 +625,7 @@ public void handleCloseWithStatusFrame() throws Exception {
625625
expect(ctx.channel()).andReturn(ch);
626626

627627
ChannelFuture future = unit.mock(ChannelFuture.class);
628-
expect(future.addListener(FIRE_EXCEPTION_ON_FAILURE)).andReturn(future);
628+
expect(future.addListener(CLOSE)).andReturn(future);
629629

630630
WebSocketServerHandshaker handshaker = unit.get(WebSocketServerHandshaker.class);
631631
expect(handshaker.close(ch, retain)).andReturn(future);

0 commit comments

Comments
 (0)