Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(firehose): serialise flusher ticks so two polls cannot buffer the same records (#4141)

Priamo Germosen86493303cdfb
diff --git a/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java b/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java
index 48d84c79f7..25205598cf 100644
--- a/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/firehose/FirehoseService.java
@@ -237,7 +237,14 @@ public class FirehoseService implements ResourceProvider {
buffers.keySet().forEach(this::flushByKey);
}
- void tickSafely() {
+ /**
+ * Ticks never overlap: {@code flushExecutor} is single threaded, and the source poll is a
+ * read of the shard iterator, a fetch and an advance that is not atomic across the three, so
+ * two concurrent ticks would fetch the same records twice and buffer them twice. Tests drive
+ * this method directly alongside the scheduled tick, which is the only way a second caller
+ * arises, so the guarantee is stated here rather than left to the executor.
+ */
+ synchronized void tickSafely() {
try {
pollKinesisSources();
flushDueBuffers(clock.instant());