Skip to content

Commit

Permalink
Unwrap completion exception in RedisHandshake #2234
Browse files Browse the repository at this point in the history
We now unwrap potentially wrapped exceptions to be able to inspect the cause. This can happen in an async flow when the HELLO command invocation fails.
  • Loading branch information
mp911de committed Nov 22, 2022
1 parent b913b4a commit 4d07dfd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/RedisHandshake.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;

import io.lettuce.core.codec.StringCodec;
Expand Down Expand Up @@ -98,6 +99,10 @@ private CompletionStage<?> tryHandshakeResp3(Channel channel) {

hello.whenComplete((settings, throwable) -> {

if (throwable instanceof CompletionException) {
throwable = throwable.getCause();
}

if (throwable != null) {
if (isUnknownCommand(throwable)) {
fallbackToResp2(channel, handshake);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package io.lettuce.core;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.*;

import javax.inject.Inject;

Expand All @@ -29,8 +29,10 @@
import io.lettuce.core.protocol.CommandArgs;
import io.lettuce.core.protocol.CommandType;
import io.lettuce.test.LettuceExtension;
import io.lettuce.test.WithPassword;
import io.lettuce.test.condition.EnabledOnCommand;
import io.lettuce.test.settings.TestSettings;
import reactor.core.publisher.Mono;

/**
* Integration test for authentication.
Expand Down Expand Up @@ -62,4 +64,23 @@ void authAsJohn(RedisClient client) {

connection.close();
}

@Test
@Inject
void ownCredentialProvider(RedisClient client) {

RedisURI uri = RedisURI.builder().withHost(TestSettings.host()).withPort(TestSettings.port()).withAuthentication(() -> {
return Mono.just(RedisCredentials.just(null, TestSettings.password()));
}).build();

client.setOptions(ClientOptions.create());
WithPassword.run(client, () -> {

StatefulRedisConnection<String, String> connection = client.connect(uri);

assertThat(connection.sync().ping()).isEqualTo("PONG");
connection.close();
});
}

}

0 comments on commit 4d07dfd

Please sign in to comment.