Skip to content
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

appender: name spawned thread #2219

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions tracing-appender/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,23 @@ impl<T: Write + Send + Sync + 'static> Worker<T> {

/// Creates a worker thread that processes a channel until it's disconnected
pub(crate) fn worker_thread(mut self) -> std::thread::JoinHandle<()> {
thread::spawn(move || {
loop {
match self.work() {
Ok(WorkerState::Continue) | Ok(WorkerState::Empty) => {}
Ok(WorkerState::Shutdown) | Ok(WorkerState::Disconnected) => {
drop(self.writer); // drop now in case it blocks
let _ = self.shutdown.recv();
return;
}
Err(_) => {
// TODO: Expose a metric for IO Errors, or print to stderr
thread::Builder::new()
.name("tracing-appender".to_string())
.spawn(move || {
loop {
match self.work() {
Ok(WorkerState::Continue) | Ok(WorkerState::Empty) => {}
Ok(WorkerState::Shutdown) | Ok(WorkerState::Disconnected) => {
drop(self.writer); // drop now in case it blocks
let _ = self.shutdown.recv();
return;
}
Err(_) => {
// TODO: Expose a metric for IO Errors, or print to stderr
}
}
}
}
})
})
.expect("failed to spawn `tracing-appender` non-blocking worker thread")
}
}