-
Notifications
You must be signed in to change notification settings - Fork 7
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
Pool connections using bb8 #115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good overall. Left a few minor nits. Then afterwords I'll test. Don't forget to rebase on main.
use eyre::{bail, ensure, Context, OptionExt}; | ||
use async_trait::async_trait; | ||
use eyre::{bail, ensure, eyre, Context, OptionExt}; | ||
use eyre::{ContextCompat, Result}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer eyre::WrapErr instead of Context and eyre::OptionExt instead of ContextCompat
async fn is_valid(&self, framed: &mut Self::Connection) -> Result<(), Self::Error> { | ||
let framed = framed | ||
.as_mut() | ||
.wrap_err("connection was dropped due to panic")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use eyre::OptionExt
let framed = Framed::new(bi); | ||
Ok(Some(framed)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let framed = Framed::new(bi); | |
Ok(Some(framed)) | |
Ok(Some(Framed::new(bi))) |
async fn get_framed(&self) -> Result<DropConnectionOnPanic<'_>> { | ||
let pooled_connection = self.pool.get().await.map_err(|e| match e { | ||
bb8::RunError::User(eyre) => { | ||
eyre.wrap_err("get from connection pool failed") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eyre.wrap_err("get from connection pool failed") | |
eyre.wrap_err("could not get framed stream from connection pool") |
Moves from an async worker (bad abstraction) to a connection pool.
bb8
does not have an obvious way to kill connections involved in a panic, so as a (hopefully temporary) workaround, a wrapper is used that checks for panics on drop and, if so, replaces the connection with aNone
before it is returned to the pool, at which point it is identified as dead viahas_broken
.Draft asit compiles but is not yet tested.