From ef37d836a079a14b3e0ca39a9d5be0dbc7a82efb Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 1 Jun 2023 16:28:26 -0700 Subject: [PATCH] Log error, don't crash, if socket closes mid-send --- src/conn.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/conn.rs b/src/conn.rs index 151e091..ac90dba 100644 --- a/src/conn.rs +++ b/src/conn.rs @@ -746,9 +746,11 @@ impl Connection { match packet.packet_type() { PacketType::Syn | PacketType::Fin | PacketType::Data => { if let Some(state) = self.state_packet() { - self.socket_events - .send(SocketEvent::Outgoing((state, self.cid.peer.clone()))) - .expect("outgoing channel should be open if connection is not closed"); + let event = SocketEvent::Outgoing((state, self.cid.peer.clone())); + if self.socket_events.send(event).is_err() { + tracing::warn!("Cannot transmit state packet: socket closed channel"); + return; + } } } PacketType::State | PacketType::Reset => {} @@ -1113,9 +1115,10 @@ impl Connection { sent_packets.on_transmit(packet.seq_num(), packet.packet_type(), payload, len, now); unacked.insert_at(packet.seq_num(), packet.clone(), sent_packets.timeout()); - socket_events - .send(SocketEvent::Outgoing((packet, dest.clone()))) - .expect("outgoing channel should be open if connection is not closed"); + let outbound = SocketEvent::Outgoing((packet, dest.clone())); + if socket_events.send(outbound).is_err() { + tracing::warn!("Cannot transmit packet: socket closed channel"); + } } }