File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,8 @@ use std::sync::atomic::AtomicUsize;
7070use std:: sync:: atomic:: Ordering ;
7171use std:: sync:: Mutex ;
7272use take_mut:: take;
73+
74+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
7375// }}}
7476
7577// {{{ Serializer
@@ -293,12 +295,25 @@ where
293295 }
294296 let drain = self . drain ;
295297 let join = builder
296- . spawn ( move || loop {
297- match rx. recv ( ) . unwrap ( ) {
298- AsyncMsg :: Record ( r) => {
299- r. log_to ( & drain) . unwrap ( ) ;
298+ . spawn ( move || {
299+ let drain = AssertUnwindSafe ( & drain) ;
300+ // catching possible unwinding panics which can occur in used inner Drain implementation
301+ if let Err ( panic_cause) = catch_unwind ( move || loop {
302+ match rx. recv ( ) {
303+ Ok ( AsyncMsg :: Record ( r) ) => {
304+ if r. log_to ( & * drain) . is_err ( ) {
305+ eprintln ! ( "slog-async failed while writing" ) ;
306+ return ;
307+ }
308+ }
309+ Ok ( AsyncMsg :: Finish ) => return ,
310+ Err ( recv_error) => {
311+ eprintln ! ( "slog-async failed while receiving: {recv_error}" ) ;
312+ return ;
313+ }
300314 }
301- AsyncMsg :: Finish => return ,
315+ } ) {
316+ eprintln ! ( "slog-async failed with panic: {panic_cause:?}" )
302317 }
303318 } )
304319 . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments