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

Make splice atomic #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

badeend
Copy link
Contributor

@badeend badeend commented Feb 14, 2024

Partly a PR, partly a question: what is supposed to happen with the already read data in case the write within splice fails?

Currently, wasmtime throws the data away.

Can we make it such that the splice implementation first reads into a per-stream stash and only then attempt to write it into the destination output stream? Future reads then first check if there is any data in its local stash, before calling the backing implementation.

I think this is in line with Linux' splice and sendfile

@pchickey
Copy link

Yes, we should follow the lead of splice(2) and not throw away read bytes if a write fails. I was lazy about doing that correctly in wasmtime's implementation, but the behavior as it exists today is not desirable.

@guybedford what is the jco behavior for splice?

@badeend
Copy link
Contributor Author

badeend commented Aug 26, 2024

@badeend
Copy link
Contributor Author

badeend commented Sep 16, 2024

@alexcrichton Do you agree with this approach? Notably:

Can we make it such that the splice implementation first reads into a per-stream stash and only then attempt to write it into the destination output stream? Future reads then first check if there is any data in its local stash, before calling the backing implementation.

@alexcrichton
Copy link
Contributor

I think that's a good approach yeah, and I would agree that it'd be surprising to lose data otherwise via a splice, so sounds like a good change to me!

@sunfishcode
Copy link
Member

Do we have any use cases that need atomic behavior?

One of the original motivations for adding splice was for implementing std::io::copy in Rust, and Rust's API doesn't guarantee atomic behavior.

When we added splice, the expected use cases were where the only thing one is going to do with the data is write it to the output, so if the write fails, the caller isn't going to try to read the data again and do something else with it. I'm hesitant here to add more burden on implementers if we don't have a usecase that needs it.

@badeend
Copy link
Contributor Author

badeend commented Sep 26, 2024

Do we have any use cases that need atomic behavior?

If not, then we should at least document this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants