Skip to content

Commit

Permalink
bb8: try to avoid panics in production code
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Feb 1, 2024
1 parent 460dc96 commit ced6412
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions bb8/src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ where
pool: Arc<SharedPool<M>>,
) {
if approval.is_some() {
self.pending_conns -= 1;
self.num_conns += 1;
#[cfg(debug_assertions)]
{
self.pending_conns -= 1;
self.num_conns += 1;
}
#[cfg(not(debug_assertions))]
{
self.pending_conns = self.pending_conns.saturating_sub(1);
self.num_conns = self.num_conns.saturating_add(1);
}
}

// Queue it in the idle queue
Expand All @@ -91,11 +99,26 @@ where
}

pub(crate) fn connect_failed(&mut self, _: Approval) {
self.pending_conns -= 1;
#[cfg(debug_assertions)]
{
self.pending_conns -= 1;
}
#[cfg(not(debug_assertions))]
{
self.pending_conns = self.pending_conns.saturating_sub(1);
}
}

pub(crate) fn dropped(&mut self, num: u32, config: &Builder<M>) -> ApprovalIter {
self.num_conns -= num;
#[cfg(debug_assertions)]
{
self.num_conns -= num;
}
#[cfg(not(debug_assertions))]
{
self.num_conns = self.num_conns.saturating_sub(num);
}

self.wanted(config)
}

Expand Down

0 comments on commit ced6412

Please sign in to comment.