Skip to content

PooledConnection return on panic #211

@SafariMonkey

Description

@SafariMonkey

In PooledConnection's Drop impl, it seems that unless the connection has been extracted via take, the connection is unconditionally returned to the queue. This concerns me, as the Drop may have been invoked during unwinding, and the connection itself may have initiated the panic, and as such may contain broken invariants, which has_broken and is_valid may not be appropriate to detect.

I considered wrapping my connection type in a type that detects panics on drop, but, of course, the inner connection type does not get dropped if it's returned to the pool. It might be possible to wrap the connection type after .get()ing it from the pool in a type that extracts and drops it on drop if the thread is panicking, but that seems awkward and error-prone. (I tried the outer wrapper approach, but take() isn't public.)

Is there currently an intended way to handle panics? If there isn't, then if my concern is valid, might it be reasonable to (maybe based on a flag) check std::thread::panicking in the Drop implementation, and drop the connection instead of returning it to the pool if it's true?

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