8000 TimedOut error when has_broken = true · Issue #167 · djc/bb8 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
TimedOut error when has_broken = true #167
Closed
@mdecimus

Description

@mdecimus

Hi,

I found what seems to be a bug. When multiple connections return true on has_broken(), all future requests to get() fail with a TimedOut error. This code can be used to reproduce the problem:

use std::{convert::Infallible, time::Duration};

struct ConnectionManager;
struct Connection;

#[async_trait::async_trait]
impl bb8::ManageConnection for ConnectionManager {
    type Connection = Connection;
    type Error = Infallible;

    async fn connect(&self) -> Result<Self::Connection, Self::Error> {
        Ok(Connection)
    }

    async fn is_valid(&self, _: &mut Self::Connection) -> Result<(), Self::Error> {
        Ok(())
    }

    fn has_broken(&self, _: &mut Self::Connection) -> bool {
        true
    }
}

#[tokio::test]
async fn pool() {
    let pool = bb8::Pool::builder()
        .max_size(5)
        .connection_timeout(Duration::from_secs(10))
        .build(ConnectionManager)
        .await
        .unwrap();

    let mut futures = Vec::new();

    for _ in 0..10 {
        let pool = pool.clone();
        futures.push(tokio::spawn(async move {
            let conn = pool.get().await.unwrap();
            drop(conn);
        }));
    }

    for future in futures {
        future.await.unwrap();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0