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

get error "pool timed out while waiting for an open connection" #1137

Closed
Json1949 opened this issue Mar 26, 2021 · 4 comments
Closed

get error "pool timed out while waiting for an open connection" #1137

Json1949 opened this issue Mar 26, 2021 · 4 comments
Labels
db:mysql Related to MySQL pool Related to SQLx's included connection pool waiting for author

Comments

@Json1949
Copy link

Json1949 commented Mar 26, 2021

Sqlx reported an error when I used the script to loop the request
Here's my code

rust main.rs

#[derive(Serialize)]
struct JsonResp {
    id: i32
}

#[derive(Clone)]
struct AppState {
    pub pool: MySqlPool
}

#[async_std::main]
async fn main() -> tide::Result<()> {

    let pool = MySqlPoolOptions::new()
        .max_connections(5)
        .connect("mysql://root:123456@localhost:3306/blog").await?;

    println!("{:?}", pool);

    let app_state = AppState { pool: pool };

    let mut app = tide::with_state(app_state);
    app.at("/test").get(test);
    app.listen("127.0.0.1:8080").await?;
    Ok(())
}


async fn test(req: Request<(AppState)>) -> tide::Result<tide::Body> {

    println!("order_shoes");
    let app_state = req.state();
    let pool = &app_state.pool;
    println!("{:?}", pool);

    let (id, color) = sqlx::query_as::<_, (i32, String)>("select id, color from tags where id = 1").fetch_one(pool).await?;
    println!("{}", color);

    Ok(tide::Body::from_json( &JsonResp { id: id})?)
}

test script

ruby_send.rb

require 'net/http'
require 'uri'

loop do
  url = URI.parse("http://localhost:8080/test")
  response = Net::HTTP.get(url)
  p response
end

start.shell

for i in {1..20}; do
 nohup ruby ruby_send.rb > send.log &
done

Run the start.shell and There was no response to the request

@DanielJoyce
Copy link

If there are only 5 connections and you loop fast enough sqlx will timeout waiting for a connection to be freed.

Either increase number of connections or increase timeout.

@abonander
Copy link
Collaborator

@MrZhouYj please try your test against the latest master to see if #1149 fixed the problem, or try 0.5.2 when it's deployed.

@abonander
Copy link
Collaborator

@MrZhouYj please try to reproduce with sqlx 0.5.2

@abonander abonander added db:mysql Related to MySQL pool Related to SQLx's included connection pool waiting for author labels Apr 16, 2021
@Json1949
Copy link
Author

@MrZhouYj please try to reproduce with sqlx 0.5.2

Looks okay, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
db:mysql Related to MySQL pool Related to SQLx's included connection pool waiting for author
Projects
None yet
Development

No branches or pull requests

3 participants