Skip to content

Commit

Permalink
Fix: duplicate message for Interest stream fails seq check in Publish…
Browse files Browse the repository at this point in the history
…Ack (#1005)

Co-authored-by: Scott Fauerbach <[email protected]>
  • Loading branch information
MauriceVanVeen and scottf authored Oct 6, 2023
1 parent 0542422 commit 92da51e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/nats/client/api/PublishAck.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public PublishAck(Message msg) throws IOException, JetStreamApiException {
if (stream == null) {
throw new IOException("Invalid JetStream ack.");
}
seq = JsonValueUtils.readLong(jv, SEQ, 0);
if (seq == 0) {
seq = JsonValueUtils.readLong(jv, SEQ, -1);
if (seq < 0) {
throw new IOException("Invalid JetStream ack.");
}
domain = JsonValueUtils.readString(jv, DOMAIN);
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/io/nats/client/api/PublishAckTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ public void testValidAck() {
}
}

@Test
public void testValidAckForDuplicateWithSeq0() {
String json = "{\"stream\":\"test-stream\",\"seq\":0,\"domain\":\"test-domain\", \"duplicate\" : true }";

try {
PublishAck ack = new PublishAck(getDataMessage(json));
assertEquals("test-stream", ack.getStream());
assertEquals("test-domain", ack.getDomain());
assertEquals(0, ack.getSeqno());
assertTrue(ack.isDuplicate());
}
catch (Exception e) {
fail("Unexpected Exception: " + e.getMessage());
}
}

@Test
public void testThrowsOnGarbage() {
assertThrows(JetStreamApiException.class, () -> {
Expand Down

0 comments on commit 92da51e

Please sign in to comment.