Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ public EventKind onMessageSend(MessageSendParams params) throws JSONRPCError {
ResultAggregator.EventTypeAndInterrupt etai = null;
try {
EventConsumer consumer = new EventConsumer(queue);

// This callback must be added before we start consuming. Otherwise,
// any errors thrown by the producerRunnable are not picked up by the consumer
Comment on lines +166 to +167
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The comment clarifies the order of operations, but the API could be refactored to enforce this order, preventing potential race conditions. Consider modifying ResultAggregator.consumeAndBreakOnInterrupt to accept the producerRunnable as a parameter to encapsulate the logic of adding the callback before consumption.

producerRunnable.addDoneCallback(consumer.createAgentRunnableDoneCallback());
etai = resultAggregator.consumeAndBreakOnInterrupt(consumer);

Expand Down Expand Up @@ -204,8 +207,9 @@ public Flow.Publisher<StreamingEventKind> onMessageSendStream(MessageSendParams
try {
EventConsumer consumer = new EventConsumer(queue);

// This callback must be added before we start consuming. Otherwise,
// any errors thrown by the producerRunnable are not picked up by the consumer
Comment on lines +210 to +211
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the previous comment, consider refactoring ResultAggregator.consumeAndEmit to accept the producerRunnable to prevent potential race conditions by design.

producerRunnable.addDoneCallback(consumer.createAgentRunnableDoneCallback());

Flow.Publisher<Event> results = resultAggregator.consumeAndEmit(consumer);

Flow.Publisher<Event> eventPublisher =
Expand Down