Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write method calls send_data before poll_ready #78

Open
WesleyRosenblum opened this issue Feb 8, 2022 · 5 comments · May be fixed by #81
Open

write method calls send_data before poll_ready #78

WesleyRosenblum opened this issue Feb 8, 2022 · 5 comments · May be fixed by #81
Labels
C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: easy. A task that would be a great starting point for a new contributor.

Comments

@WesleyRosenblum
Copy link

On stream.rs#L28-L29, stream.send_data is called prior to stream.poll_ready.

stream.poll_ready should be called first, similar to as described in https://docs.rs/futures/latest/futures/sink/trait.Sink.html#tymethod.poll_ready.

Thanks for considering this issue, and let me know if you have any questions!

@seanmonstar
Copy link
Member

Huh, good point. I don't recall why the order was switched there... Granted, technically we aren't using Sink specifically, but the pattern is definitely similar.

@camshaft
Copy link
Contributor

camshaft commented Feb 8, 2022

Another option would be to rename the methods to something like set_data and poll_send_data, which it seems like is how it's being used currently.

But if we're considering an API change, I'm not sure why we couldn't just change it to:

fn poll_send_data(&mut self, buf: &mut dyn Buf) -> Poll<Result<()>>;

It would remove the need for the stream implementation to convert/store the buffer and make things a bit simpler, IMO.

@seanmonstar
Copy link
Member

That change would require that the bytes always be copied out, no? I guess unless it was already a Bytes. Whereas currently, by passing ownership of the impl Buf, a QUIC implementation could copy, but it could also choose to store it, kinda like h2 does.

@camshaft
Copy link
Contributor

camshaft commented Feb 8, 2022

Not necessarily. If the caller used copy_to_bytes with chunk lengths the Buf impl would specialize on it:

let len = buf.chunk().len();
let bytes = buf.copy_to_bytes(len);

(see, for example, impl Buf for Bytes)

@seanmonstar
Copy link
Member

Yea, that's what I meant by if it was already a Bytes. If it was a custom impl Buf, it would end up being copied into a Bytes... I think there's merit in discussing if the API around sending data is the right one. But for this specific issue, it also looks like that's a simple bug: the calls should be reversed.

@seanmonstar seanmonstar added E-easy Effort: easy. A task that would be a great starting point for a new contributor. C-bug Category: bug. Something is wrong. This is bad! labels Feb 9, 2022
@seanmonstar seanmonstar linked a pull request Feb 10, 2022 that will close this issue
ten3roberts added a commit to security-union/h3 that referenced this issue Apr 12, 2023
This changes the `quic::SendStream` trait to closer mimic the
`AsyncWrite` trait, but using a `impl Buf` rather than `&[u8]` which
removes the need to allocate and copy the byte slice to store it if
needed.

[s2n-quic::SendStream](https://github.com/aws/s2n-quic/blob/bf20c6dd148153802929a2514b444dcf5dd37fd1/quic/s2n-quic-h3/src/s2n_quic.rs#L364) uses this to enqueue the bytes for sending, which would require allocating if `&[u8]` was used.

Issue hyperium#78 discusses this API change which would remove the need for intermediate buffering.

See: hyperium#78 (comment)
@ten3roberts ten3roberts mentioned this issue Apr 12, 2023
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug. Something is wrong. This is bad! E-easy Effort: easy. A task that would be a great starting point for a new contributor.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants