-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flux.cache causing flow to hang indefinitely #2711
Comments
I was able to reproduce it indeed. Due to the timing, there is some arbitrary nature to the reproducer, but I found that I could simplify the example and get a deterministic reproducer by using a Here is my version of the repro case: @Test
void test() throws InterruptedException {
//vtsStop(); //only important because I added the test in FluxReplayTest.java
VirtualTimeScheduler vts = VirtualTimeScheduler.create();
AtomicInteger sourceLoad = new AtomicInteger();
AtomicInteger pollStart = new AtomicInteger();
final AtomicInteger pollEnd = new AtomicInteger();
Flux<String> flow = getSource()
.doOnSubscribe(__ -> log.info("Loading source #" + sourceLoad.incrementAndGet()))
.cache(Duration.ofSeconds(1), vts)
.flatMap(v -> {
if (v == 1) {
pollStart.incrementAndGet();
}
else if (v == 5) { //this assume a 5 element source
pollEnd.incrementAndGet();
}
return process(pollStart.get() + "_" + v, vts);
}, 2)
.repeat(3);
StepVerifier.create(flow)
.expectNextCount(4 * 5)
.expectComplete()
.verify(Duration.ofSeconds(300));
}
private Flux<Integer> getSource() {
return Flux.just(1, 2, 3, 4, 5)
.doOnRequest(r -> log.info("source.request({})", r == Long.MAX_VALUE ? "unbounded" : r))
.hide();
}
private Mono<String> process(String channel, VirtualTimeScheduler timeScheduler) {
if (channel.equals("2_4")) {
timeScheduler.advanceTimeBy(Duration.ofMillis(1001));
}
return Mono.fromCallable(() -> {
log.info("Processing: {}", channel);
return channel;
});
} |
As a temporary workaround
|
we unfortunately still haven't got to the bottom of this, moving it back in the 3.4.x backlog |
This commit reworks the FluxReplay implementation to use a prefetch strategy, as well as state-machine-like state to better keep track of demand, avoiding hanging. The operator is driven by active subscribers so the next prefetch happens only when all the subscribers have consumed a particular element. To enable that, now every implementation has an index actively utilized to identify if specific element is a trigger for the next prefetch. In case there are no subscribers, the prefetch strategy is self-driven and requests more when there are produced N elements into the cache The downside is that historySize 0 is not supported anymore. It is believed that it wasn't really relevant, but on the slight possibility that this is actually used out there, the FluxReplay is replaced by a FluxPublish transparently when 0 is passed to the operator method. On the `Sinks` side, since part of the implementation is shared, the same limitation is present, but we are more proactive in rejecting a zero limit / historySize there. The bet is that for this younger API, such incoherent usage hasn't emerged yet. Fixes #2711. Co-authored-by: Simon Baslé <sbasle@vmware.com>
Hi there, apparently I do have an application that breaks when upgrading reactor-core from 3.4.9 to 3.4.10. A Thanks, |
@ginkel, feel free to open an issue if you know how to explain your problem |
The idea is to implement continuous data processing based on the source (i.e. continuously polling portion data for every account). Cache is used to repeat processing flow for the same source but periodically reload the source. In addition, we need to limit concurrency for the processing.
After several iterations flow hangs indefinitely. Trying to troubleshoot more but it looks like a combination of
cache
&flatMap
withconcurrency
causing this behavior.Expected Behavior
Flow is repeated indefinitely
Actual Behavior
Flow hangs indefinitely
Steps to Reproduce
Here is a simplified flow that could be used to reproduce the issue.
Your Environment
java -version
): 14uname -a
): Darwin M-C02YP071JHD4 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64The text was updated successfully, but these errors were encountered: