Skip to content

Commit 228c761

Browse files
authored
Use a scope guard for decrementing queue length. (#2865)
1 parent 1e3e8db commit 228c761

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

crates/core/src/host/module_host.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,13 @@ impl ModuleHost {
577577
.with_label_values(&self.info.database_identity)
578578
.observe(queue_length as f64);
579579
}
580+
// Ensure that we always decrement the gauge.
581+
let timer_guard = scopeguard::guard((), move |_| {
582+
// Decrement the queue length gauge when we're done.
583+
// This is done in a defer so that it happens even if the reducer call panics.
584+
queue_length_gauge.dec();
585+
queue_timer.stop_and_record();
586+
});
580587

581588
// Operations on module instances (e.g. calling reducers) is blocking,
582589
// partially because the computation can potentialyl take a long time
@@ -593,8 +600,7 @@ impl ModuleHost {
593600
});
594601
self.job_tx
595602
.run(move |inst| {
596-
queue_timer.stop_and_record();
597-
queue_length_gauge.dec();
603+
drop(timer_guard);
598604
f(inst)
599605
})
600606
.await

0 commit comments

Comments
 (0)