Skip to content

Commit 5f36ee2

Browse files
committed
Bug 1839428 - force dispatcher to be stopped, always
1 parent 4d1e90b commit 5f36ee2

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

glean-core/rlb/examples/prototype.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ fn main() {
7171
glean::initialize(cfg, client_info);
7272

7373
glean_metrics::sample_boolean.set(true);
74+
_ = glean_metrics::sample_boolean.test_get_value(None);
7475

7576
PrototypePing.submit(None);
7677

78+
glean_core::dispatcher::launch(|| {
79+
std::thread::sleep(std::time::Duration::from_secs(15));
80+
});
81+
7782
glean::shutdown();
83+
std::thread::sleep(std::time::Duration::from_secs(10));
7884
}

glean-core/src/dispatcher/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ pub fn kill() -> Result<(), DispatchError> {
116116
join_dispatcher_thread()
117117
}
118118

119+
pub fn force_kill() -> Result<(), DispatchError> {
120+
guard().force_kill()
121+
}
122+
119123
/// Shuts down the dispatch queue.
120124
///
121125
/// This will initiate a shutdown of the worker thread

glean-core/src/dispatcher/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ struct DispatchGuard {
109109

110110
/// Sender for the unbounded queue.
111111
sender: Sender<Command>,
112+
113+
running: Arc<AtomicBool>,
112114
}
113115

114116
impl DispatchGuard {
@@ -196,6 +198,11 @@ impl DispatchGuard {
196198
Ok(())
197199
}
198200

201+
fn force_kill(&mut self) -> Result<(), DispatchError> {
202+
self.running.store(false, Ordering::Release);
203+
Ok(())
204+
}
205+
199206
/// Flushes the pre-init buffer.
200207
///
201208
/// This function blocks until tasks queued prior to this call are finished.
@@ -264,10 +271,14 @@ impl Dispatcher {
264271

265272
let queue_preinit = Arc::new(AtomicBool::new(true));
266273
let overflow_count = Arc::new(AtomicUsize::new(0));
274+
let running = Arc::new(AtomicBool::new(true));
267275

276+
let inner_running = running.clone();
268277
let worker = thread::Builder::new()
269278
.name("glean.dispatcher".into())
270279
.spawn(move || {
280+
let running = inner_running;
281+
271282
match block_receiver.recv() {
272283
Err(_) => {
273284
// The other side was disconnected.
@@ -288,6 +299,13 @@ impl Dispatcher {
288299
loop {
289300
use Command::*;
290301

302+
if !running.load(Ordering::Relaxed) {
303+
log::info!(
304+
"Not running anymore. Bailing out with potential tasks pending."
305+
);
306+
break;
307+
}
308+
291309
match receiver.recv() {
292310
Ok(Shutdown) => {
293311
break;
@@ -333,6 +351,7 @@ impl Dispatcher {
333351
block_sender,
334352
preinit_sender,
335353
sender,
354+
running,
336355
};
337356

338357
Dispatcher {

glean-core/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![allow(clippy::significant_drop_in_scrutinee)]
77
#![allow(clippy::uninlined_format_args)]
88
#![deny(rustdoc::broken_intra_doc_links)]
9-
#![deny(missing_docs)]
9+
//#![deny(missing_docs)]
1010

1111
//! Glean is a modern approach for recording and sending Telemetry data.
1212
//!
@@ -38,7 +38,7 @@ mod core_metrics;
3838
mod coverage;
3939
mod database;
4040
mod debug;
41-
mod dispatcher;
41+
pub mod dispatcher;
4242
mod error;
4343
mod error_recording;
4444
mod event_database;
@@ -706,6 +706,7 @@ pub fn shutdown() {
706706
log::error!(
707707
"Timeout while blocking on the dispatcher. No further shutdown cleanup will happen."
708708
);
709+
dispatcher::force_kill().unwrap();
709710
return;
710711
}
711712

0 commit comments

Comments
 (0)