apupier opened a new pull request, #31115: URL: https://github.com/apache/camel/pull/31115
JIRA: https://issues.apache.org/jira/browse/CAMEL-26778 ## Problem `ReactorStreamsServiceTest` (`testTo`, `testToWithExchange`, `testToFunctionWithExchange`) is flaky: it sometimes blocks for the full 30 seconds of `Mono.block(Duration.ofSeconds(30))` and fails with `Timeout on blocking read`. ## Cause This is a race in production code, not in the tests. `ReactorStreamsService.doRequest()` built its result as: ```java Mono.create(sink -> exchange.addOnCompletion(...)) .doOnSubscribe(subs -> consumer.process(data, ...)); ``` Reactor runs `doOnSubscribe` **before** the `create` callback. The exchange was therefore handed to the thread pool of the `ReactiveStreamsConsumer` before the completion callback was registered. When a pool thread completed the exchange first, `onComplete` was never seen, the `Mono` never emitted, and the caller waited until its timeout. ## Fix Register the completion callback and then call `consumer.process(...)` inside the `Mono.create` callback, in that order, so the completion cannot be missed. ## Tests Added `testToCompletesWhenRouteIsFasterThanSubscription` (2000 sequential `crs.to(...)` calls). Without the fix it reliably timed out after 30s; with the fix the whole `ReactorStreamsServiceTest` class runs in ~4s. All `ReactorStreamsService*Test` classes pass, and `ReactorStreamsServiceTest` was run 3 more times in a row without failure. Note: the `testToFunction` `assertTrue` failure in the JIRA description comes from an older latch-based version of the test that CAMEL-24763 already replaced. --- _Claude Code (IBM Bob) on behalf of @apupier_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
