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

Avoid out-of-sync state by handling java.lang.Error #3132

Open
tishun opened this issue Jan 17, 2025 · 3 comments
Open

Avoid out-of-sync state by handling java.lang.Error #3132

tishun opened this issue Jan 17, 2025 · 3 comments
Labels
status: mre-available Minimal Reproducible Example is available type: improvement An improvement to the existing implementation

Comments

@tishun
Copy link
Collaborator

tishun commented Jan 17, 2025

Improvement Request

There ara multitude of issues reported where the driver would report a variation of the following message:

java.lang.UnsupportedOperationException: io.lettuce.core.output.ValueOutput does not support set(long)

As a hypothesis we believe that some error, such as - but not necessarily - OutOfMemory, causes the event loop to become out of sync.

See #3117 (comment)

Related issues:

Describe the solution you'd like

A suggested solution is to catch such errors, terminate the connection and complete any remaining commands exceptionally.

Describe alternatives you've considered

N/A

@tishun tishun added type: improvement An improvement to the existing implementation for: team-attention An issue we need to discuss as a team to make progress labels Jan 17, 2025
@tishun tishun removed the for: team-attention An issue we need to discuss as a team to make progress label Jan 20, 2025
@henriklundstrom
Copy link

@tishun

As a hypothesis we believe that some error, such as - but not necessarily - OutOfMemory, causes the event loop to become out of sync.

I hope this can be helpful in some way:

The out-of-sync state can be reproduced in the existing test case subscriberCompletingWithExceptionShouldBeHandledSafely by substituting this RuntimeException with any kind of JVM fatal error, such as a LinkageError. It produces this failure:

[ERROR] Failures: 
[ERROR]   ReactiveConnectionIntegrationTests.subscriberCompletingWithExceptionShouldBeHandledSafely expectation "expectNext(valueB)" failed (expected value: valueB; actual value: valueA)

Alternatively, this more extensive test case can be used to illustrate the behaviour where GET(keyX) -> valueY:

@Test
@Inject
void showcaseInconsistentResponsesOnJvmFatal(RedisClient client) {

    // A separate reactive connection is created to avoid interference with other tests
    RedisReactiveCommands<String, String> reactiveCommands = client.connect().reactive();

    // Prepare a state in the Redis
    StepVerifier.create(Flux.concat(
                    reactiveCommands.set("keyA", "valueA"),
                    reactiveCommands.set("keyB", "valueB"),
                    reactiveCommands.set("keyC", "valueC"),
                    reactiveCommands.set("keyD", "valueD")
                    )
            ).expectNextCount(4)
            .verifyComplete();

    /**
     * Purposefully throw a JVM fatal error in the onNext callback.
     *
     * The error is not propagated to the subscriber.
     * Therefore, the StepVerifier can not be used, as it would hang indefinitely.
     *
     * The throwable needs to be a "jvmFatal" as defined by:
     * {@link reactor.core.Exceptions#isJvmFatal(Throwable)}
     */
    reactiveCommands.get("keyA").doOnNext(foo -> { throw new LinkageError("jvmFatal1"); }).subscribe();

    // Unlike a normal test case, these assertions are used to demonstrate the inconsistent behavior
    StepVerifier.create(reactiveCommands.get("keyB")).expectError(LinkageError.class).verify();
    StepVerifier.create(reactiveCommands.get("keyC")).expectNext("valueB").verifyComplete();
    StepVerifier.create(reactiveCommands.get("keyD")).expectNext("valueC").verifyComplete();
}

@tishun tishun added the status: mre-available Minimal Reproducible Example is available label Feb 18, 2025
@tishun
Copy link
Collaborator Author

tishun commented Feb 18, 2025

Hey @henriklundstrom ,

thanks for the sample code! As soon as the team has prioritized this item we will go over it and try to provide a fix.

@tishun
Copy link
Collaborator Author

tishun commented Feb 20, 2025

See also https://github.com/nordnet/lettuce-out-of-order

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: mre-available Minimal Reproducible Example is available type: improvement An improvement to the existing implementation
Projects
None yet
Development

No branches or pull requests

2 participants