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

EventBus is not receiving any ReconnectFailedEvent when ConnectionWatchDog has detected a RedisCommandExecutionException. #3162

Open
zmo123 opened this issue Feb 4, 2025 · 4 comments
Labels
status: waiting-for-feedback We need additional information before we can continue type: bug A general bug

Comments

@zmo123
Copy link

zmo123 commented Feb 4, 2025

Bug Report

Current Behavior

I am using AWS Elasticache Redis instance, I am also using AWS Secret Manager rotation for storing secret for Redis connection, where we have an policy of automatic secret rotating.

I have subscribed to the eventBus provided by Lettuce, I expect to receive a ReconnectFailedEvent if my password has expired or rotated in connection to Redis, I am currently using AWS Elasticache Redis instance for caching purposing.I want to be able to reestablish connection by refreshing the context to build the new lettuceConnectionFactory.

Stack trace
2025-02-04 16:19:48.190 - WARN [catalog-data-services,,,,] 1 --- [oEventLoop-12-3] [] i.l.core.protocol.ConnectionWatchdog : Cannot reconnect to [xxxxxxx]: io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled. java.util.concurrent.CompletionException: io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled. ~~ at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332) ~~ at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:347) ~~ at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1141) ~~ at java.base/java.util.concurrent.Comp ---- Caused by: io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled. ~~ at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:147) ~~ at io.lettuce.core.internal.ExceptionFactory.createExecutionException(ExceptionFactory.java:116) ~~ ... 31 common frames omitted ~~

Input Code

Input Code
 @Bean
    public void configuration(){
        log.info("RedisConnectionEventListener bean created");
        lettuceConnectionFactory.getClientResources().eventBus().get().subscribe(event -> {
            log.info("RedisConnectionEventListener received event: " + event);
            if (event instanceof ReconnectFailedEvent) {
                LocalTime currentTime = LocalTime.now();

                // Get the current minute of the hour
                int currentMinute = currentTime.getMinute();

                //if current minute is same as previous minute, return
                if(atomicInt.get() == currentMinute){
                    log.info("current ReconnectFailedEvent is being handled at minute:"  + currentMinute);
                    return;
                }

                //update current minute
                atomicInt.set(currentMinute);

                String localAddress = ((ReconnectFailedEvent) event).localAddress().toString();
                String remoteAddress = ((ReconnectFailedEvent) event).remoteAddress().toString();
                log.error("Redis connection failed: " + event + " localAddress:" + localAddress + " RemoteAddress:" + remoteAddress);
                // Handle connection failure
                if(lock.tryLock()) {
                    try {
                        refreshScopeHandler.refreshBeans();
                        scheduler.schedule(() -> {
                            atomicInt.set(-1);
                            log.info("reset RedisConnectionEventListener, current minute: " + currentMinute);
                        }, 1, TimeUnit.MINUTES);
                    } finally {
                        lock.unlock();
                    }
                }else{
                    log.info("Failed to acquire lock");
                }
            }
        });
    }

Expected behavior/code

I expect to receive a ReconnectFailedEvent if my password has expired or rotated in connection to Redis, I am currently using AWS Elasticache Redis instance for caching purposing.I want to be able to reestablish connection by refreshing the context to build the new lettuceConnectionFactory. However no such event is received and I am not able to handle any error related to WRONGPASS.

Environment

  • Lettuce version(s): [e.g. 5.0.0.RELEASE, 4.2.2.Final]
  • Redis version: [e.g. 4.0.9]

Possible Solution

Additional context

@zmo123
Copy link
Author

zmo123 commented Feb 4, 2025

c.j.p.c.c.RedisConnectionEventListener : RedisConnectionEventListener received event: {}

subsequent event received are shown as blank for some reason?

@zmo123
Copy link
Author

zmo123 commented Feb 25, 2025

hi any help or update is appreciated

@tishun
Copy link
Collaborator

tishun commented Feb 26, 2025

Hey @zmo123 ,

the team is busy on some other urgent tasks, I plan to take a look on Friday and give you some feedback

@tishun
Copy link
Collaborator

tishun commented Feb 28, 2025

Hey @zmo123 ,

could you also provide a sample of how you set the credentials provider up?

My tests on a simpler setup show that we do get ReconnectFailedEvent and we also have an integration test that tests this.
So it must be something in your specific setup that we need to reproduce in order to fix the issue.

Ideally a minimum reproducible example would help speed this up a lot!

@tishun tishun added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage labels Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-feedback We need additional information before we can continue type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants