From f9060323528b308d5ae78addca095160b3206be0 Mon Sep 17 00:00:00 2001 From: Artyom Sakharilenko Date: Fri, 16 Jun 2023 12:11:01 +0300 Subject: [PATCH 1/3] `err.to_string()` instead of deprecated `err.description()`. --- lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib.rs b/lib.rs index 72d431a..f5871c4 100644 --- a/lib.rs +++ b/lib.rs @@ -62,7 +62,6 @@ use slog::{BorrowedKV, Level, Record, RecordStatic, SingleKV, KV}; use slog::{Key, OwnedKVList, Serializer}; use slog::Drain; -use std::error::Error; use std::fmt; use std::sync; use std::{io, thread}; @@ -222,7 +221,7 @@ impl From> for AsyncError { fn from(err: std::sync::PoisonError) -> AsyncError { AsyncError::Fatal(Box::new(io::Error::new( io::ErrorKind::BrokenPipe, - err.description(), + err.to_string(), ))) } } From 674a228362e046d5a0753c703c1ea0a46216cceb Mon Sep 17 00:00:00 2001 From: Artyom Sakharilenko Date: Fri, 16 Jun 2023 12:27:32 +0300 Subject: [PATCH 2/3] Avoid panics in async drain thread. --- lib.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib.rs b/lib.rs index f5871c4..2f7fb28 100644 --- a/lib.rs +++ b/lib.rs @@ -70,6 +70,8 @@ use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; use std::sync::Mutex; use take_mut::take; + +use std::panic::{catch_unwind, AssertUnwindSafe}; // }}} // {{{ Serializer @@ -293,12 +295,25 @@ where } let drain = self.drain; let join = builder - .spawn(move || loop { - match rx.recv().unwrap() { - AsyncMsg::Record(r) => { - r.log_to(&drain).unwrap(); + .spawn(move || { + let drain = AssertUnwindSafe(&drain); + // catching possible unwinding panics which can occur in used inner Drain implementation + if let Err(panic_cause) = catch_unwind(move || loop { + match rx.recv() { + Ok(AsyncMsg::Record(r)) => { + if r.log_to(&*drain).is_err() { + eprintln!("slog-async failed while writing"); + return; + } + } + Ok(AsyncMsg::Finish) => return, + Err(recv_error) => { + eprintln!("slog-async failed while receiving: {recv_error}"); + return; + } } - AsyncMsg::Finish => return, + }) { + eprintln!("slog-async failed with panic: {panic_cause:?}") } }) .unwrap(); From 2d261b12ecd2db3d587726fa9e1aa0e8d888276e Mon Sep 17 00:00:00 2001 From: Artyom Sakharilenko Date: Fri, 16 Jun 2023 12:58:49 +0300 Subject: [PATCH 3/3] CHANGELOG + version bump. --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 128a2c8..863dd5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 2.8.0 - 2023-06-16 + +* Call of deprecated `err.description()` replaced with `err.to_string()`. +* Avoided all catchable panics in async drain thread. + ## 2.7.0 - 2021-07-29 * Fix license field to be a valid SPDX expression diff --git a/Cargo.toml b/Cargo.toml index 5bef620..c42aeb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "slog-async" -version = "2.7.0" +version = "2.8.0" authors = ["Dawid Ciężarkiewicz "] description = "Asynchronous drain for slog-rs" keywords = ["slog", "logging", "log", "asynchronous"]