Skip to content

Commit

Permalink
fix #4660: incrementing the fetch for ping/pong
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins authored and vietj committed Apr 14, 2023
1 parent 800bc18 commit 6d6d440
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/io/vertx/core/http/impl/WebSocketImplBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ private void receiveFrame(WebSocketFrameInternal frame) {
context.dispatch(frame.binaryData(), handler);
}
break;
case PING:
case PONG:
fetch(1);
break;
}
}

Expand Down
25 changes: 25 additions & 0 deletions src/test/java/io/vertx/core/http/WebSocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2480,6 +2480,31 @@ public void testServerWebSocketPingPong() {
}));
await();
}

@Test
public void testWebSocketPausePing() throws InterruptedException {
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST));
server.webSocketHandler(ws -> {
ws.pongHandler(buff -> {
assertEquals("ping", buff.toString());
ws.close();
});
ws.writePing(Buffer.buffer("ping"));
}).listen(onSuccess(v -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/").onComplete(onSuccess(ws -> {
ws.pause();
ws.handler(buff -> {
fail("Should not receive a buffer");
});
ws.fetch(1);
ws.endHandler(v2 -> {
testComplete();
});
}));
}));
await();
}

@Test
public void testServerWebSocketPingExceeds125Bytes() {
Expand Down

0 comments on commit 6d6d440

Please sign in to comment.