Skip to content

Commit 1176315

Browse files
authored
Merge pull request #346 from blackbeam/active-wait-requests-fix
Properly update `active_wait_requests` metric (fix #335)
2 parents 293e9ef + 7656f43 commit 1176315

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/conn/pool/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct Waitlist {
110110
}
111111

112112
impl Waitlist {
113+
/// Returns `true` if pushed.
113114
fn push(&mut self, waker: Waker, queue_id: QueueId) -> bool {
114115
// The documentation of Future::poll says:
115116
// Note that on multiple calls to poll, only the Waker from
@@ -122,10 +123,9 @@ impl Waitlist {
122123
//
123124
// This means we have to remove first to have the most recent
124125
// waker in the queue.
125-
self.remove(queue_id);
126-
self.queue
127-
.push(QueuedWaker { queue_id, waker }, queue_id)
128-
.is_none()
126+
let occupied = self.remove(queue_id);
127+
self.queue.push(QueuedWaker { queue_id, waker }, queue_id);
128+
!occupied
129129
}
130130

131131
fn pop(&mut self) -> Option<Waker> {
@@ -135,6 +135,7 @@ impl Waitlist {
135135
}
136136
}
137137

138+
/// Returns `true` if removed.
138139
fn remove(&mut self, id: QueueId) -> bool {
139140
self.queue.remove(&id).is_some()
140141
}
@@ -1016,6 +1017,13 @@ mod test {
10161017
drop(only_conn);
10171018

10181019
assert_eq!(0, pool.inner.exchange.lock().unwrap().waiting.queue.len());
1020+
// metrics should catch up with waiting queue (see #335)
1021+
assert_eq!(
1022+
0,
1023+
pool.metrics()
1024+
.active_wait_requests
1025+
.load(std::sync::atomic::Ordering::Relaxed)
1026+
);
10191027
}
10201028

10211029
#[tokio::test]

0 commit comments

Comments
 (0)