-
Notifications
You must be signed in to change notification settings - Fork 121
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
Hanging connections; Pool issue? #57
Comments
code, for posterity. clickhouse-rs = "=0.1.14"
futures = "0.1.29"
tokio = "0.1.22"
env_logger = "0.7.0" use clickhouse_rs::Pool;
use futures::Future;
use std::io::{stdin, stdout, Write};
fn main() {
// Important: set pool_max and pool_min to 1
//let database_url = "tcp://localhost:9001?pool_max=1&pool_min=1";
env_logger::init();
let database_uri = std::env::args().nth(1).expect("please enter db uri");
let pool = Pool::new(database_uri);
let mut buf = String::new();
loop {
print!("press enter to run query:");
stdout().flush().expect("could not flush stdout");
stdin()
.read_line(&mut buf)
.expect("could not read line from stdin");
let fut = pool
.get_handle()
.and_then(move |c| c.query("select 1;").fetch_all())
.and_then(move |(_, block)| {
println!("query success: {:?}", block);
Ok(())
})
.map_err(|err| println!("database error: {}", err));
tokio::run(fut);
}
} |
logs, where
If run with v0.1.16 instead of 0.1.14, the following line is added (after a few minutes?)
|
Hello, It's incorrect usage. You shouldn't use the same connection pool with multiple runtimes (each call of This example should look like: use clickhouse_rs::{errors::Error, Pool};
use futures::Future;
use std::io::{stdin, stdout, Write};
type BoxFuture<T> = Box<dyn Future<Item = T, Error = Error> + Send>;
fn loop_(pool: Pool, mut buf: String) -> BoxFuture<()> {
print!("press enter to run query:");
stdout().flush().expect("could not flush stdout");
stdin()
.read_line(&mut buf)
.expect("could not read line from stdin");
let fut = pool
.get_handle()
.and_then(move |c| c.query("select 1;").fetch_all())
.and_then(move |(_, block)| {
println!("query success: {:?}", block);
Ok(())
})
.and_then(move |_| loop_(pool, buf));
Box::new(fut)
}
fn main() {
env_logger::init();
let database_uri = std::env::args().nth(1).expect("please enter db uri");
let pool = Pool::new(database_uri);
let done = loop_(pool, String::new()).map_err(|err| println!("database error: {}", err));
tokio::run(done);
} I think |
Ah, thanks, I didn't know that multiple runtimes would create an issue. Funnily, I guess the incorrect usage seen here may not even be present in our app, since we just use the system runner in Actix. It's kind of an artifact of trying to present a clean minimum example of the bug we're seeing in our app. However, I did want to confirm about whether v0.1.16 will fix the other problems we're seeing. We were seeing hanging across all queries with v0.1.14, even though I don't believe we're creating multiple runtimes. I had guessed that the hanging might be related to Even with your fix to the example, I'm still able to trigger reconnect by cutting the connection, and then observe hanging (v0.1.16 will at least timeout error, where I'm seeing about 3min between So I guess in the end I'm still asking three questions:
And thanks for taking the time to answer this question, it's really helpful and it also helps us be able to contribute in the future. |
|
Hello,
While using clickhouse in our project, we've been finding that the connection to clickhouse will sometimes hang. While the upcoming v0.1.16 will solve an issue that fixes one of the symptom, I believe that there may be a more fundamental issue.
The minimal example is at https://github.com/hwchen/clickhouse-hang. The basic idea is that when using
pool_max=1
, running two queries in series will cause the second query to enterreconnect
logic (as seen from the logs) and then hang. In v0.1.16, a timeout error will eventually occur, freeing up the connection and a query can be sent again. In v0.1.14, the hang is indefinite.Assuming that this behavior is real, I think that it's likely that our usage of
pool_max
much greater than 1 has been hiding it to some extent.Let me know if you need any more details. Also, @jspeis and I are both happy to investigate further and/or work on a fix.
Sorry, I wasn't able to find yet what code in clickhouse is responsible, but I wanted to point out the behavior first in case you could provide some direction.
The text was updated successfully, but these errors were encountered: