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

How far should we aim to achieve abortable ops in AsyncRead/AsyncWrite? #2509

Open
kazuki0824 opened this issue Oct 14, 2021 · 0 comments
Open

Comments

@kazuki0824
Copy link
Contributor

kazuki0824 commented Oct 14, 2021

Recent work

Recently I posted a PR (#2507) to implement an abortable feature to futures_util::io::copy_buf(), which provides an abort handle for the copy operation, and enables to stop copying in the middle.

A problem left behind

But the solution I mentioned above is just concerned with copy operation. Remembering #2156 , he claims that abortable is required for all common IO operations, so I think this PR is only a partial solution.

In #2156 (comment) , @withoutboats pointed out that for some I/Os, the end of the stream is defined by the termination token in the stream, not by the condition that the return value of syscall read() is zero. From what I understand, in that situation, the termination is detected by repeatedly reading the stream as large as the given termination token and pattern matching against it. To trigger stop when the termination token is received, external abort handle for I/O object must be exposed.

My another suggestion

To realize abort in the middle, we must have kind of a channel like an Arc<AtomicBool> as a member. So introducing a new struct is necessary.
I suggest creating a new struct AbortableReader, similar to BufReader, and adding fn add_abortable_registration(r: AbortRegistration) -> AbortableReader<Self> into AsyncRead/AsyncWrite, instead of directly implementing them. Or, it’ll be also better to add abortable function to BufReader and switch it by const generic bool. A non-switchable one doesn't sound preferrable mainly because of performance loss from atomic ops.

Pros and cons

Pros: The method can solve #2156 partly by seemingly minimal modification.
Cons: Hardship expected in future work. To solve #2156 completely, we have to consider more that

  • When multiple IO objects are involved, such as copy, you need something like "if any one of them receives an abort, terminate all of them", and that seems to be very tricky. It is because we need to propagate his Cancellation hook to all the involved I/O objects.

What to discuss

How far do we aim to achieve abortable ops in AsyncRead/AsyncWrite?

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

No branches or pull requests

1 participant