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

Support for Mysql #40

Closed
thegenius opened this issue Jan 10, 2020 · 5 comments
Closed

Support for Mysql #40

thegenius opened this issue Jan 10, 2020 · 5 comments
Labels

Comments

@thegenius
Copy link

thegenius commented Jan 10, 2020

I'am new to this library and try to write an mysql example.
Cargo.toml:
async-std = { version = "1.4.0", features = [ "attributes" ] }
sqlx = {version = "0.1.3", features = [ "mysql" ]}
anyhow = "1.0.26"

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

    let pool_result = MySqlPool::new(
        "mysql://root:123456@localhost:3306/test"
    ).await;
    let mut pool = match pool_result {
        Ok(p) => p,
        Err(_) => panic!("pool create faild")
    };

    let user_id = 1u32;
    let stat = sqlx::query("SELECT * FROM hello WHERE id = $1").bind(user_id);

    // blocked here, and will never return
    let row_result = stat.fetch_one(&mut pool).await;

    // can not reach here
    let row = match row_result {
        Ok(data) => data,
        Err(_) => panic!("panic at row")
    };
    Ok(())
}

From this example, maybe mysql support is poor, maybe there is some bug in this library.
I open this issue to request for more mysql support.

@mehcode
Copy link
Member

mehcode commented Jan 10, 2020

@thegenius Thank you for opening this.

Can you confirm that you can connect to mysql using the command line?

I tested your example locally and it works if your password is right but blocks forever if its not. That's definitely a bug that needs fixing. We need to add an integration test of "bad password" (probably for both mysql and postgres to make sure we're handling that error response from the database correctly).

@mehcode mehcode added bug question Further information is requested labels Jan 10, 2020
@mehcode
Copy link
Member

mehcode commented Jan 10, 2020

Also can you confirm your MySQL version?

@thegenius
Copy link
Author

@mehcode
OS: osx10.14 (x86_64)
DB: mysql-5.7.27

So happy to get response from you. I think this library is on the right way to make rust excellent. And I'm glad to join in. Maybe the first step is helping test the library. And join you in the future.

@mehcode
Copy link
Member

mehcode commented Jan 11, 2020

We've confirmed the bug and have a small test case that is reproducible. Basically, you're hitting a bug in the Pool where a connection failure is retried for 30 seconds until it finally stops. If you let it hang for 30 seconds, it should error with a timeout error.

A quick work-around to help if you still can't connect is to try opening a regular connection just before the pool. That will give you a proper error message so you can debug your connection issue.

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

    // Open a new connection and immediately drop it
    let _ =  MySqlConnection::open(
        "mysql://root:123456@localhost:3306/test"
    ).await?;

    let pool_result = MySqlPool::new(
        "mysql://root:123456@localhost:3306/test"
    ).await;
    let mut pool = match pool_result {
        Ok(p) => p,
        Err(_) => panic!("pool create faild")
    };
    
    // [...]
}

As for the actual fix, that will be up in the next couple days. We've discovered a couple other corner cases in the Pool while going through it and will be fixing those as well before we make a release.

Thanks again for the report. 🙇‍♂️

@mehcode mehcode removed the question Further information is requested label Jan 11, 2020
mehcode added a commit that referenced this issue Jan 11, 2020
@mehcode
Copy link
Member

mehcode commented Jan 11, 2020

This should be fixed in v0.1.4

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

No branches or pull requests

2 participants