From 7b67badbf81a92011c6a84dfbd0c618fa8ddc734 Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Wed, 19 Jul 2023 11:50:17 +0300 Subject: [PATCH 1/3] fix: Fix regression when sync id check is disabled --- .../flow/server/communication/LongPollingCacheFilter.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flow-server/src/main/java/com/vaadin/flow/server/communication/LongPollingCacheFilter.java b/flow-server/src/main/java/com/vaadin/flow/server/communication/LongPollingCacheFilter.java index 246b09c4260..93b53f24587 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/communication/LongPollingCacheFilter.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/communication/LongPollingCacheFilter.java @@ -76,7 +76,10 @@ public BroadcastAction filter(String broadcasterId, AtmosphereResource r, String uuid = r.uuid(); int lastSeenOnClient = session.getAttribute(SEEN_SERVER_SYNC_ID, Integer.class); - if (pushMessage.alreadySeen(lastSeenOnClient)) { + if (lastSeenOnClient == -1) { + return new BroadcastAction(BroadcastAction.ACTION.CONTINUE, + message); + } else if (pushMessage.alreadySeen(lastSeenOnClient)) { getLogger().trace( "Discarding message {} for resource {} as client already seen {}. {}", pushMessage.serverSyncId, uuid, lastSeenOnClient, From e78624c2997640d103bd427b989738c30feb58dc Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Wed, 19 Jul 2023 12:23:35 +0300 Subject: [PATCH 2/3] Add unit test --- .../communication/LongPollingCacheFilterTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java b/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java index a19c2eddd4e..d97a910877e 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java @@ -81,6 +81,19 @@ public void filter_notLongPollingTransport_continueWithCurrentMessage() { verifyMessageIsNotCached(); } + @Test + public void filter_syncIdCheckDisabled_continueWithCurrentMessage() { + setTransport(AtmosphereResource.TRANSPORT.LONG_POLLING); + setSeenServerSyncIdHeader(-1); + BroadcastAction action = filter.filter("broadcasterId", resource, + originalMessage, message); + Assert.assertEquals(ACTION.CONTINUE, action.action()); + Assert.assertSame( + "Message should not be altered by filter if server sync id header is missing", + message, action.message()); + verifyMessageIsNotCached(); + } + @Test public void filter_missingLastSeenServerSyncId_continueWithCurrentMessage() { setTransport(AtmosphereResource.TRANSPORT.LONG_POLLING); @@ -224,4 +237,4 @@ private void simulatePushConnection() { private void verifyMessageIsNotCached() { Mockito.verifyNoInteractions(cache); } -} \ No newline at end of file +} From ff3f510ea14a3c540a8dda0ec4827501fc1ac6aa Mon Sep 17 00:00:00 2001 From: Tatu Lund Date: Wed, 19 Jul 2023 13:01:24 +0300 Subject: [PATCH 3/3] Fix message --- .../flow/server/communication/LongPollingCacheFilterTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java b/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java index d97a910877e..93d587318d6 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/communication/LongPollingCacheFilterTest.java @@ -89,7 +89,7 @@ public void filter_syncIdCheckDisabled_continueWithCurrentMessage() { originalMessage, message); Assert.assertEquals(ACTION.CONTINUE, action.action()); Assert.assertSame( - "Message should not be altered by filter if server sync id header is missing", + "Message should not be altered by filter if syncId check is disabled", message, action.message()); verifyMessageIsNotCached(); }