diff --git a/sctp/src/association/mod.rs b/sctp/src/association/mod.rs index 656b0d17e..cec94accb 100644 --- a/sctp/src/association/mod.rs +++ b/sctp/src/association/mod.rs @@ -488,7 +488,7 @@ impl Association { let done = Arc::new(AtomicBool::new(false)); let name = Arc::new(name); - while !done.load(Ordering::Relaxed) { + 'outer: while !done.load(Ordering::Relaxed) { //log::debug!("[{}] gather_outbound begin", name); let (packets, continue_loop) = { let mut ai = association_internal.lock().await; @@ -512,9 +512,8 @@ impl Association { // Doing it this way, tokio schedules this work on a dedicated blocking thread, this future is suspended, and the read_loop can make progress match tokio::task::spawn_blocking(move || raw.marshal_to(&mut buf).map(|_| buf)) .await - .unwrap() { - Ok(mut buf) => { + Ok(Ok(mut buf)) => { let raw = buf.as_ref(); if let Err(err) = net_conn.send(raw.as_ref()).await { log::warn!("[{}] failed to write packets on net_conn: {}", name2, err); @@ -527,9 +526,21 @@ impl Association { buf.clear(); buffer = Some(buf); } - Err(err) => { + Ok(Err(err)) => { log::warn!("[{}] failed to serialize a packet: {:?}", name2, err); } + Err(err) => { + if err.is_cancelled() { + log::debug!( + "[{}] task cancelled while serializing a packet: {:?}", + name, + err + ); + break 'outer; + } else { + log::error!("[{}] panic while serializing a packet: {:?}", name, err); + } + } } //log::debug!("[{}] sending {} bytes done", name, raw.len()); }