Skip to content

Question about detecting dead connection #1572

Closed
@wangkekekexili

Description

@wangkekekexili

I'm not sure whether this is a feature request, an issue on my end or just a simple question so please forgive me for not completely following the template.

Current Behavior

The issue we are encountering is that during the scale-up process of aws Redis, we are seeing io.lettuce.core.RedisCommandTimeoutException errors.

We are using non-cluster mode Redis and connecting to reader endpoint. When scaling up aws Redis, DNS domain name remains the same but IP changes; that's when client starts to show errors. After some time, ConnectionWatchdog seems to notice the channel is inactive. Lettuce reconnects and it gets the updated IP address.

I think the timeout issue is caused by client side still holding the existing connection when the peer disappears. It doesn't know the peer disappears and keeps sending requests using the existing connection. I'm wondering what I can do here to detect the dead connection? Could ConnectionWatchdog be updated to catch dead connection and try re-connect?

Input Code

I'm using this simple code for testing the behavior:

fun main(args: Array<String>) = runBlocking<Unit> {
    val ro = <reader-endpoint-here>
    launch(Dispatchers.IO) {
        val clientResources = DefaultClientResources.builder()
            .dnsResolver(DirContextDnsResolver()).build()
        val redisClient = RedisClient.create(clientResources, RedisURI.create(ro)).apply {
            options = ClientOptions
                .builder()
                .socketOptions(
                    SocketOptions
                        .builder()
                        .connectTimeout(Duration.ofMillis(500L))
                        .keepAlive(true)
                        .build()
                )
                .timeoutOptions(
                    TimeoutOptions
                        .builder()
                        .fixedTimeout(Duration.ofMillis(500L))
                        .build()
                )
                .build()
        }
        val statefulRedisConnection = redisClient.connect()
        val redisCommands = statefulRedisConnection.sync()
        while (true) {
            try {
                redisCommands.get("hello")
            } catch (ex: Exception) {
                println(ex)
            }
            delay(Duration.ofMillis(500))
        }
    }
}

Environment

  • Lettuce version: 5.2.2.RELEASE
  • Redis version: 5.0.6

Any suggestions would be greatly appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions