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

Test connection before initializing pool #104

Open
Pzixel opened this issue May 13, 2020 · 0 comments
Open

Test connection before initializing pool #104

Pzixel opened this issue May 13, 2020 · 0 comments

Comments

@Pzixel
Copy link

Pzixel commented May 13, 2020

Consider following code

let postgres_manager = ConnectionManager::<PgConnection>::new("postgre://bac");
let pool = Pool::new(postgres_manager)?;

Currently it produces following output:

2020-05-13T16:30:07.777244900+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:07.778244700+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
2020-05-13T16:30:08.179240800+03:00 ERROR r2d2 - missing "=" after "postgre://bac" in connection info string
...

It returns Err in the end, but it takes time and unnessessary requests to db.

I think probably it should check if connection is ok before initializing pool. Something like:

    pub fn new(manager: M) -> Result<Pool<M>, Error> {
        let _test_connecction = manager.connect()?;
        Pool::builder().build(manager)
    }
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

1 participant