Skip to content

Easy way to create dead-lock in retain function #445

@xoac

Description

@xoac

Hi, small modification of retain function can lead to dead-lock.

    let interval = Duration::from_secs(30);
    let max_age = Duration::from_secs(60);
    tokio::spawn(async move {
        loop {
            tokio::time::sleep(interval).await;
            pool.retain(|_, metrics| {
                let should_be_remove = pool.status().size > 1 && metrics.last_used() > max_age;
                !should_be_removed
            });
        }
    });

Above calls self.inner.slots.lock().unwrap() twice in retain function because status() also blocks. The easiest way would be to make status lock-free. Status is already documented as not consistent so I think it should be possible to achieve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-coreArea: Core / deadpoolenhancementNew feature or requestquality of lifeImprovements to the API resulting in a better quality of life for the users of deadpool.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions