Skip to content

Commit 5c6dd9b

Browse files
NiteshKantstevegury
authored andcommitted
Respond to keep-alive with response flag off. (#194)
#### Problem `ServerReactiveSocket` upon receiving a `KeepAlive` frame responds with a `KeepAlive` frame as an ack. This ack MUST not have respond flag set to true. Doing so will result in an infinite loop of keep-alive frames sent between the peers. #### Modification `ServerReactiveSocket` responds with the respond flag turned off. #### Result No infinite loop of keep-alive frames.
1 parent e69ae87 commit 5c6dd9b

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

reactivesocket-core/src/main/java/io/reactivesocket/ServerReactiveSocket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ private Publisher<Void> handleFireAndForget(int streamId, Publisher<Void> result
327327

328328
private Publisher<Void> handleKeepAliveFrame(Frame frame) {
329329
if (Frame.Keepalive.hasRespondFlag(frame)) {
330-
return Px.from(connection.sendOne(frame))
330+
return Px.from(connection.sendOne(Frame.Keepalive.from(Frame.NULL_BYTEBUFFER, false)))
331331
.doOnError(errorConsumer);
332332
}
333333
return Px.empty();

reactivesocket-core/src/test/java/io/reactivesocket/ServerReactiveSocketTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public void testHandleKeepAlive() throws Exception {
4343
rule.connection.addToReceivedBuffer(Frame.Keepalive.from(Frame.NULL_BYTEBUFFER, true));
4444
Frame sent = rule.connection.awaitSend();
4545
assertThat("Unexpected frame sent.", sent.getType(), is(FrameType.KEEPALIVE));
46-
assertThat("Unexpected keep-alive frame respond flag.", Frame.Keepalive.hasRespondFlag(sent), is(true));
46+
/*Keep alive ack must not have respond flag else, it will result in infinite ping-pong of keep alive frames.*/
47+
assertThat("Unexpected keep-alive frame respond flag.", Frame.Keepalive.hasRespondFlag(sent), is(false));
4748
}
4849

4950

0 commit comments

Comments
 (0)