Skip to content
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

Result is lost when published on another executor #986

Closed
trueinsider opened this issue Feb 27, 2019 · 5 comments
Closed

Result is lost when published on another executor #986

trueinsider opened this issue Feb 27, 2019 · 5 comments
Labels
type: bug A general bug
Milestone

Comments

@trueinsider
Copy link
Contributor

trueinsider commented Feb 27, 2019

Bug Report

Current Behavior

#905 This change introduces some kind of bug where result is lost

Input Code

RedisClient client1 = RedisClient.create("redis://localhost");
RedisClient client2 = RedisClient.create("redis://localhost");
client1.setOptions(ClientOptions.builder().publishOnScheduler(false).build());
client2.setOptions(ClientOptions.builder().publishOnScheduler(true).build());
RedisReactiveCommands<String, String> redis1 = client1.connect().reactive();
RedisReactiveCommands<String, String> redis2 = client2.connect().reactive();
int counter1 = 0;
int counter2 = 0;
for (int i = 0; i < 1000; i++) {
    if (redis1.eval("return 1", INTEGER).next().block() == null) counter1++;
    if (redis2.eval("return 1", INTEGER).next().block() == null) counter2++;
}
out.println(counter1);
out.println(counter2);

Expected behavior/code

Basically, counter1 == counter2 == 0 should be true, but counter2 has value 1-100 instead of 0.

Environment

  • Lettuce version(s): 5.1.4.RELEASE
  • Redis version: 5.0.0

Possible Solution

Make sure that single instance of RedisPublisher.PublishOnSubscriber will use same Executor from EventExecutorGroup for all it's operations.

Additional context

I think what happens is this:
RedisPublisher.OnNext and RedisPublisher.OnComplete are scheduled to the executor in the correct order, but since executor is non-immediate and multi-threaded race condition happens and sometimes RedisPublisher.OnComplete is executed before RedisPublisher.OnNext

@mp911de
Copy link
Collaborator

mp911de commented Feb 27, 2019

Awesome work, thanks a lot for looking into that. The issue supposedly happens only with Flux and not with Mono. We have already a bit of code that creates RedisPublisher:

Flux

https://github.com/lettuce-io/lettuce-core/blob/657ed8a966e0ecb305d8fd59f8b776bb3b9f9b8b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L400-L409

Mono

https://github.com/lettuce-io/lettuce-core/blob/657ed8a966e0ecb305d8fd59f8b776bb3b9f9b8b/src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java#L422-L432

The Mono code calls correctly .next() while the Flux code misses the next() call. Care to adjust your PR accordingly so we can merge it?

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Feb 27, 2019
@trueinsider
Copy link
Contributor Author

@mp911de sure, done

mp911de pushed a commit that referenced this issue Feb 27, 2019
We now use a single EventExecutor when emitting signals instead of submitting runnables to the EventExecutorGroup.
This change retains execution order and prevents race conditions of completion arrival before an actual data signal.

Original pull request: #987.
mp911de added a commit that referenced this issue Feb 27, 2019
Add author tags. Tiny reformatting.

Original pull request: #987.
mp911de pushed a commit that referenced this issue Feb 27, 2019
We now use a single EventExecutor when emitting signals instead of submitting runnables to the EventExecutorGroup.
This change retains execution order and prevents race conditions of completion arrival before an actual data signal.

Original pull request: #987.
mp911de added a commit that referenced this issue Feb 27, 2019
Add author tags. Tiny reformatting.

Original pull request: #987.
@mp911de mp911de removed the status: waiting-for-feedback We need additional information before we can continue label Feb 27, 2019
@mp911de mp911de added this to the 5.1.5 milestone Feb 27, 2019
@mp911de
Copy link
Collaborator

mp911de commented Feb 27, 2019

Thanks a lot for all your support. The fix is scheduled for 5.1.5, expect a release by next week.

@mp911de mp911de closed this as completed Feb 27, 2019
@trueinsider
Copy link
Contributor Author

@mp911de thanks for fast merge. Can you provide snapshot for the time being?

@mp911de
Copy link
Collaborator

mp911de commented Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants