-
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
A Mono
created from a Sinks.one()
sporadically turns empty
#3257
Comments
Mono
created from a Sinks.one()
sporadically turns empty
With a debugger, I finally nailed the root cause. WhyBy the time when this line inside Now, if someone subscribes to this sink's So the execution path then follows an This in principle explains the behavior observed:
Conclusions / WorkaroundsTo me this behavior directly contradicts the description given in Sinks documentation - unless this is only applicable to
So, in the case above there were no failure reported but rather an empty mono. As an immediate work-around, one could of course call I'm not sure what the "proper" fix for this might be. I can think of failing the Or perhaps make |
I was able to reproduce and was about to post something similar! Essentially, looks like a race between: reactor-core/reactor-core/src/main/java/reactor/core/publisher/SinkOneMulticast.java Lines 57 to 62 in 72b78d6
and: reactor-core/reactor-core/src/main/java/reactor/core/publisher/SinkOneMulticast.java Lines 100 to 106 in 72b78d6
Even thought the state is Here is a snippet to make it easier to reproduce: @Test
void reproduce3257() {
var sink = Sinks.<String>one();
RaceTestUtils.race(
() -> sink.tryEmitValue("value"),
() -> assertThat(sink.asMono.block()).isNotNull()
);
} |
In our code, we create a
Sink.one()
whose value is emitted from onSuccess/onError handlers of some otherMono
. A value being emitted is nevernull
.Expected Behavior
Expectation is that a mono view of that sink will never be an empty mono, due to value emitted by a sink being non-null.
Actual Behavior
Contary to our expectation, a Mono view of that sink sporadically turns empty. It happens both on Windows 10 as well as on Ubuntu 20 machines, so it is likely not something platform-specific.
Steps to Reproduce
Below is the shortest unit test I could come up with which reflects what we're doing in our production code, and when this test is run from IDE with "repeat until failure" setting, it fails the assertion about non-null Mono result quite consistently within 10-30 seconds after start.
I also added some diagnostic logging around tryEmitValue / tryEmitError, and looks like it's never an error, and never a null value being emitted, neither it's an emission failure.
The output from a failed run is like this:
Possible Solution
Your Environment
java -version
): openjdk version "11.0.16.1" 2022-07-19 LTSuname -a
): Windows 10 / 21H2 build 19044.2130, also Linux 5.4.0-96-generic SMP x86_64 GNU/LinuxThe text was updated successfully, but these errors were encountered: