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

Async Cluster: Connection is created on each request #1025

Closed
kamulos opened this issue Jan 15, 2024 · 6 comments
Closed

Async Cluster: Connection is created on each request #1025

kamulos opened this issue Jan 15, 2024 · 6 comments

Comments

@kamulos
Copy link
Contributor

kamulos commented Jan 15, 2024

I am playing around with the async cluster timeouts, and ended up in a strange situation: for each redis request I am triggering, redis-rs will call connect_and_check and create a new connection.

Initially I got in this situation by triggering a timeout and the following reconnection also lead to a timeout. My request is a simple GET.

What I am observing is that in get_connection the branch with connect_and_check is taken and succeeds. But during the next request the same branch is taken, because the connection is still None.

Is it possible, that the connection, that is created in connect_and_check in get_connection needs to be stored back into the conn_lock?

My text is just wild guessing, but the issue is quite reproducible for me, so I can dig deeper if needed.

@nihohit
Copy link
Contributor

nihohit commented Jan 16, 2024

Sounds like you reach this line, where the connection is created but not saved -

Some((addr, None)) => connect_and_check(&addr, core.cluster_params.clone())

I believe that the solution is something like

match connect_and_check::<C>(&addr, core.cluster_params.clone()).await {
    Ok(conn) => {
        let conn_clone = conn.clone();
        core.conn_lock
            .write()
            .await
            .0
            .insert(addr.clone(), async { conn_clone }.boxed().shared());
        Some((addr, conn))
    }
    Err(_) => None,
}

but I can't recreate this situation in a test, so can't verify it.
Can you please manually test this fix? and if possible, create a test case that is locally reproducible?

@kamulos
Copy link
Contributor Author

kamulos commented Jan 17, 2024

Just tested your fix: it works for me. Without it most of the time I get into the situation described above, with it never.

I am not sure how to approach a test case for it. I reproduce it by having a connection with specific settings (both timeouts 400ms and retries set to 1). This connection does a request each 400ms. I now have a cluster with one node, where I execute DEBUG SLEEP 1.5 which seems to be a good blocking time to land there in the code. Longer blocking usually leads to a panic which #968 will hopefully address.

Not really something that lends itself to a reliable test case 🤷

@nihohit nihohit mentioned this issue Jan 18, 2024
22 tasks
@nihohit
Copy link
Contributor

nihohit commented Jan 18, 2024

Ok, different take - does this solve your issue?
#1032

IMO both fixes are correct and relevant, but I want to be sure that what I think will work actually will work :)

@nihohit
Copy link
Contributor

nihohit commented Jan 18, 2024

Managed to write the world's most artificial tests for the first fix, hurrah!
#1033

@kamulos
Copy link
Contributor Author

kamulos commented Jan 19, 2024

Ok, different take - does this solve your issue? #1032

IMO both fixes are correct and relevant, but I want to be sure that what I think will work actually will work :)

Yes it does 😊 I am especially enthusiastic about this one, because it also resolves the issue of panics when I use long DEBUG SLEEP times on the server side.

Those two fixes are great, thank you!

@kamulos
Copy link
Contributor Author

kamulos commented Mar 11, 2024

Fixed in release 0.25.0

@kamulos kamulos closed this as completed Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants