Skip to content

fix: multicast event handler silently drops events when no aggregates found#25

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-build-failure-on-main
Draft

fix: multicast event handler silently drops events when no aggregates found#25
Copilot wants to merge 3 commits intomainfrom
copilot/fix-build-failure-on-main

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 6, 2026

In pub/sub systems, messages from different topics have no guaranteed delivery order. This caused ChannelSummary.onUserSubscribed to silently discard subscription events that arrived before the corresponding ChannelCreated had been processed — findByChannel returned empty, the handler did nothing, and the message was ACK'd and lost.

Root cause

MulticastEventHandlerWriter generated code that treated an empty query result as a no-op:

// Before — empty result silently dropped
var aggregates = channelSummaryRepository.findByChannel(event.channel()).stream()
    .map(aggregate -> { aggregate = aggregate.onUserSubscribed(event); return aggregate; })
    .toList();
channelSummaryRepository.saveAll(aggregates); // saveAll([]) = no-op, message ACK'd

This is inconsistent with ByReferenceEventHandlerWriter, which uses .orElseThrow() and therefore triggers the retry mechanism on missing entities.

Fix

Fail fast on empty results so PubSubUtil's retry template re-delivers the message until the target aggregate exists:

// After — throws when empty, triggering retry
var aggregates = channelSummaryRepository.findByChannel(event.channel());
if (aggregates.isEmpty()) {
    throw new IllegalStateException("No aggregates found for event: " + event);
}
channelSummaryRepository.saveAll(aggregates.stream()
    .map(aggregate -> { aggregate = aggregate.onUserSubscribed(event); return aggregate; })
    .toList());

With default config (5 retries, 1 s initial backoff), the out-of-order event is retried within the first second — well within the test's 30 s window — and succeeds once ChannelCreated has been processed.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • packages.confluent.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/prefab/prefab org.codehaus.plexus.classworlds.launcher.Launcher compile -pl annotation-processor -am --no-transfer-progress -q resources/pubsub/single/User.jav/home/REDACTED/work/prefab/prefab/pubsub/src/test/resources/pubsub--noprofile resources/pubsubgit resources/pubsubpush resources/pubsub-v resources/pubsuborigin (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/prefab/prefab org.codehaus.plexus.classworlds.launcher.Launcher compile -pl annotation-processor --no-transfer-progress -q --global nverter.java er.java nverter.java (dns block)
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.14/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.14/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.14 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.14/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/prefab/prefab org.codehaus.plexus.classworlds.launcher.Launcher -f pom.xml -B -V -e -Dfindbugs.skip -Dcheckstyle.skip -Dpmd.skip=true -Dspotbugs.skip -Denforcer.skip -Dmaven.javadoc.skip (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI and others added 2 commits April 6, 2026 05:51
Copilot AI changed the title [WIP] Fix build failure on main branch fix: multicast event handler silently drops events when no aggregates found Apr 6, 2026
Copilot AI requested a review from stijnvanbael April 6, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants