Skip to content

Commit

Permalink
Log error, don't crash, if socket closes mid-send
Browse files Browse the repository at this point in the history
  • Loading branch information
carver committed Jun 24, 2023
1 parent 3bc0778 commit 84fb93b
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,11 @@ impl<const N: usize, P: ConnectionPeer> Connection<N, P> {
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 => {}
Expand Down Expand Up @@ -1106,9 +1108,10 @@ impl<const N: usize, P: ConnectionPeer> Connection<N, P> {

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");
}
}
}

Expand Down

0 comments on commit 84fb93b

Please sign in to comment.