Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ removed).
- [Rust releases publish through OIDC](/quest/m1/release-rs-oidc.md) - release-plz publishes with trusted publishing and `CARGO_REGISTRY_TOKEN` is revoked
- [kio's clock tests pass under cargo test](/quest/m1/clock-test-process.md) - `paused_runtimes_own_their_anchors` stops depending on being first in its process
- [The JS stalled-consumer eviction test ages its groups](/quest/m1/js-cache-age-test.md) - the test drives the clock the cache reads, so it can fail
- [moq-transport-22 FETCH cost](/quest/m1/ietf22-fetch-poll-cost.md) - #7042's +12.8% instructions on draft-22 FETCH is fixed or attributed
- [An idle track poll exits cheaply](/quest/m1/idle-poll-exit.md) - a reader's poll on a track with nothing new costs a small constant, not ~3,800 instructions
- [Main is no slower than release](/quest/m1/release-perf/README.md) - every benchmark where main is slower than release is fixed or accepted with a reason, checked by a final paired run before the cut
- [Interop coverage](/quest/m1/interop-coverage/README.md) - the riskiest moq-transport features moq-net exposes get cross-implementation tests over drafts 18 and 22
Expand Down
34 changes: 0 additions & 34 deletions quest/m1/ietf22-fetch-poll-cost.md

This file was deleted.

79 changes: 67 additions & 12 deletions rs/moq-net/src/transport/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@ enum End {
}

impl Channel {
/// Whether a read would return now: a queued message or the end.
fn readable(&self) -> Poll<()> {
match !self.messages.is_empty() || self.end.is_some() {
true => Poll::Ready(()),
false => Poll::Pending,
}
}

/// Close with a reset or stop code and drop what is queued. An earlier end stands,
/// unless it was a finish the reader has not fully read.
fn abort(&mut self, end: End) {
Expand Down Expand Up @@ -477,17 +485,20 @@ impl poll::SendStream for SendStream {
return Poll::Ready(Ok(0));
}

if let Poll::Ready(err) = poll_close(&self.close, waiter) {
// Peek at the close rather than register on it: only a write that parks waits for it.
if let Some(err) = closed(&self.close) {
return Poll::Ready(Err(err));
}

let buffer = self.buffer;
let mut channel = ready!(self.channel.poll(waiter, |channel| {
let Poll::Ready(mut channel) = self.channel.poll(waiter, |channel| {
match channel.end.is_some() || channel.messages.is_empty() || channel.queued < buffer {
true => Poll::Ready(()),
false => Poll::Pending,
}
}));
}) else {
return poll_close(&self.close, waiter).map(Err);
};
if let Some(End::Stop(code)) = channel.end {
return Poll::Ready(Err(Error::Stopped(code)));
}
Expand Down Expand Up @@ -591,16 +602,17 @@ impl poll::Chunks for Chunks {
return Poll::Ready(Ok(Some(Bytes::new())));
}

// Check the close first, so a message queued before it is still read below.
let closed = poll_close(&self.close, waiter);
let Poll::Ready(mut channel) = self.channel.poll(waiter, |channel| {
match !channel.messages.is_empty() || channel.end.is_some() {
true => Poll::Ready(()),
false => Poll::Pending,
// Only a read that parks registers on the close, so a ready read costs one lock.
let mut channel = match self.channel.poll(waiter, |channel| channel.readable()) {
Poll::Ready(channel) => channel,
Poll::Pending => {
let err = ready!(poll_close(&self.close, waiter));
// Queued messages drain first, so look again: one may have landed before the close.
match self.channel.poll(waiter, |channel| channel.readable()) {
Poll::Ready(channel) => channel,
Poll::Pending => return Poll::Ready(Err(err)),
}
}
}) else {
// Queued messages drain first; only an idle stream fails with the close.
return closed.map(Err);
};

let Some(front) = channel.messages.front_mut() else {
Expand Down Expand Up @@ -968,6 +980,49 @@ mod tests {
assert!(closed(ready(b.poll_accept_uni(&noop())).err().unwrap()));
}

/// Only a parked read or write waits on the close: one that returns at once leaves no
/// registration behind, as every frame of a session pays for one.
#[test]
fn only_parked_streams_wait_on_the_close() {
let (a, b) = pair(buffer(0));
let (mut send, mut recv) = uni(&a, &b);
let counted = || {
let count = Arc::new(Count::default());
(kio::Waiter::new(Waker::from(count.clone())), count)
};

let (ready_write, ready_write_count) = counted();
assert_eq!(
ready(send.poll_write_buf(&ready_write, &mut Bytes::from_static(b"one"))).unwrap(),
3
);
let (ready_read, ready_read_count) = counted();
let chunk = ready(poll::Chunks::poll_read_chunk(recv.get_mut(), &ready_read, usize::MAX));
assert_eq!(chunk.unwrap().unwrap(), "one");

// The channel is empty, so the read parks; refill it so the write parks too.
let (parked_read, parked_read_count) = counted();
assert!(poll::Chunks::poll_read_chunk(recv.get_mut(), &parked_read, usize::MAX).is_pending());
let (mut other, _other_recv) = uni(&a, &b);
ready(write(&mut other, &Bytes::from_static(b"two"))).unwrap();
let (parked_write, parked_write_count) = counted();
assert!(
other
.poll_write_buf(&parked_write, &mut Bytes::from_static(b"x"))
.is_pending()
);

a.close(4, "bye");
assert_eq!(ready_write_count.0.load(Ordering::Relaxed), 0);
assert_eq!(ready_read_count.0.load(Ordering::Relaxed), 0);
assert!(parked_read_count.0.load(Ordering::Relaxed) > 0);
assert!(parked_write_count.0.load(Ordering::Relaxed) > 0);

let closed = |err: Error| matches!(err, Error::Session { code: 4, .. });
assert!(closed(ready(read(&mut recv, usize::MAX)).unwrap_err()));
assert!(closed(ready(write(&mut other, &Bytes::from_static(b"x"))).unwrap_err()));
}

#[test]
fn dropping_a_side_closes() {
let (a, b) = pair(Config::default());
Expand Down