Skip to content

Commit

Permalink
Discard incoming data with no embassy channel
Browse files Browse the repository at this point in the history
Otherwise we can spin forever on unhandled packets (such as stderr)
  • Loading branch information
mkj committed May 30, 2024
1 parent 5c405f1 commit 4620e15
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions embassy/src/embassy_sunset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,21 @@ impl<'a> EmbassySunset<'a> {
// Read wakers
let w = &mut inner.wakers;
if let Some((num, dt, _len)) = inner.runner.ready_channel_input() {
// TODO: if there isn't any waker waiting, could we just drop the packet?
match dt {
ChanData::Normal => w.chan_read[num.0 as usize].wake(),
ChanData::Stderr => w.chan_ext[num.0 as usize].wake(),
let waker = match dt {
ChanData::Normal => &mut w.chan_read[num.0 as usize],
ChanData::Stderr => &mut w.chan_ext[num.0 as usize],
};
if waker.occupied() {
waker.wake();
} else {
// No waker waiting for this packet, so drop it.
// This avoids the case where for example a client application
// is only reading from a Stdin ChanIn, but some data arrives
// over the write fore Stderr. Something needs to mark it done,
// since the session can't proceed until it's consumed.
if let Some(h) = &inner.chan_handles[num.0 as usize] {
inner.runner.discard_channel_input(&h)?
}
}
}

Expand Down

0 comments on commit 4620e15

Please sign in to comment.