Skip to content

Commit 8e9894e

Browse files
committed
Status missing from Close WebSocket frame issued by client, close AsyncHttpClient#1199
1 parent 5565ad1 commit 8e9894e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ private void handleFrame(Channel channel, WebSocketFrame frame, WebSocketUpgrade
182182
Channels.setDiscard(channel);
183183
CloseWebSocketFrame closeFrame = (CloseWebSocketFrame) frame;
184184
webSocket.onClose(closeFrame.statusCode(), closeFrame.reasonText());
185+
Channels.silentlyCloseChannel(channel);
185186
} else {
186187
ByteBuf buf = frame.content();
187188
if (buf != null && buf.readableBytes() > 0) {
@@ -226,9 +227,9 @@ public void handleChannelInactive(NettyResponseFuture<?> future) {
226227
WebSocketUpgradeHandler h = (WebSocketUpgradeHandler) future.getAsyncHandler();
227228
NettyWebSocket webSocket = NettyWebSocket.class.cast(h.onCompleted());
228229

229-
logger.trace("Connection was closed abnormally (that is, with no close frame being sent).");
230+
logger.trace("Connection was closed abnormally (that is, with no close frame being received).");
230231
if (webSocket != null)
231-
webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being sent).");
232+
webSocket.close(1006, "Connection was closed abnormally (that is, with no close frame being received).");
232233
} catch (Throwable t) {
233234
logger.error("onError", t);
234235
}

client/src/main/java/org/asynchttpclient/netty/ws/NettyWebSocket.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static io.netty.buffer.Unpooled.wrappedBuffer;
1717
import static java.nio.charset.StandardCharsets.UTF_8;
1818
import io.netty.channel.Channel;
19-
import io.netty.channel.ChannelFutureListener;
2019
import io.netty.handler.codec.http.HttpHeaders;
2120
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
2221
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
@@ -135,7 +134,7 @@ public boolean isOpen() {
135134
@Override
136135
public void close() {
137136
if (channel.isOpen()) {
138-
channel.writeAndFlush(new CloseWebSocketFrame()).addListener(ChannelFutureListener.CLOSE);
137+
channel.writeAndFlush(new CloseWebSocketFrame(1000, "normal closure"));
139138
}
140139
}
141140

client/src/test/java/org/asynchttpclient/ws/CloseCodeReasonMessageTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void onCloseWithCode() throws Exception {
4747
websocket.close();
4848

4949
latch.await();
50-
assertTrue(text.get().startsWith("1000"));
50+
assertTrue(text.get().startsWith("1000"), "Expected a 1000 code but got " + text.get());
5151
}
5252
}
5353

0 commit comments

Comments
 (0)