News for hackers. Stuff that matters.
Re:Async Rust is not safe with io_uring by ajross on Wednesday October 30, 2024 @01:37PM (#41997980)
> If that task has cancelled its interest in this syscall, they should instead clean up the resources owned by that CQE.

So, first: how is that not consistent with the contention that the bug is due to a collision in the meaning of "asynchronous"? You're describing, once more, a synchronous operation ("when ... cancel") on a data structure that doesn't support that ("the kernel writes ..." on its own schedule).

And second: the English language text of your solution has race conditions. How do you prevent reading from the buffer after the beginning of "cancel" and before the "dispatch"? You need some locking in there, which you don't in general async code. Ergo it's a paradigm clash. Developers, you among them it seems, don't really understand the requirements of a truly async process and get confused trying to shoehorn it into a "callbacks with context switch" framework like rust async.

[dead]
Re:Async Rust is not safe with io_uring by ajross on Wednesday October 30, 2024 @02:53PM (#41998828)
I think we just have to end this, your tone is just out of control and you're doing the "assume bad faith" trick really badly. But to pick out some bits where I genuinely think you're getting confused:

> Rust has ample facilities for preventing you from reading from the buffer after cancellation

The linked bug is a race condition. It's not about "after" and if you try to reason about it like that you'll just recapitulate the mistakes. And yes, rust has facilities to prevent race conditions, but they're synchronization tools and not part of async, and lots of developers (ahem) seem not to understand the requirements.

Re:Async Rust is not safe with io_uring by withoutboats3 on Wednesday October 30, 2024 @03:05PM (#41998965)
Again you’re just wrong.

Based on this post, when you drop a monoio TcpListener nothing happens. If there is an accept inflight, when it completes the reactor wakes your task, which ignores the wake up and goes back to sleep. INSTEAD when you drop the TcpListener it should cancel interest in this event with the reactor, and when the event completes the reactor should clean up the state for the complete event (which means closing the newly open file descriptor in this case).

Does this involve synchronization? Yes! Surprise surprise, when you share state between concurrent processes (whether they be tasks, threads, processes, or userspace and the kernel) you need some form of synchronization. When you say things like “Rust’s facilities to prevent race conditions [are] synchronizations tools and not part of async” you are speaking nonsense, because async Rust in all its forms are built on these synchronization primitives, whether they be atomic variables or system mutex’s or what have you.

Re:Async Rust is not safe with io_uring by blinzy on Wednesday October 30, 2024 @03:45PM (#41999377)
Unbelievable! how bloody rude can you be?

To the moderators (dang), do people get to keep their account here just because they're a "famous" poster despite writing the way they're doing all over this post? I'm assuming other posters have been banned for substantially less aggressive behaviour...

Re:Async Rust is not safe with io_uring by skavi on Saturday November 02, 2024 @05:57AM (#42025261)
> Developers, you among them it seems, don't really understand the requirements of a truly async process and get confused trying to shoehorn it into a "callbacks with context switch" framework like rust async.

This is an odd thing to say about someone who has written a correct solution to the problem which triggered this discussion.

Also, you really need to define what truly async means. Many layers of computing are async or not async depending on how you look at them.

Re:Async Rust is not safe with io_uring by ajross on Sunday November 03, 2024 @09:27AM (#42033229)
Saw this show up after the fact. Maybe it's safe enough for me to try to re-engage: The point I was trying to make, to deafening jeering, is that the linked bug is a really very routine race conditions that is "obvious" to people like me coming from a systems programming background who deal with parallelism concerns all the time. It looks interesting and weird in the context of an async API precisely because async APIs work to hide this kind of detail (in this case, the fact that the events being added to the queue are in a parallel context and racing with the seemingly-atomic "cancel" operation).

APIs to deal with things like io-uring (or DMA device drivers, or shared memory media streams, etc...) tend necessarily to involve explicit locking all the way up at the top of the API to make the relationship explicit. Async can't do that, because there's nowhere to put the lock (it only understands "events"), and so you need to synthesize it (maybe by blocking the cancelling thread until the queue drains), which is complicated and error prone.

This isn't unsolvable. But it absolutely is a paradigm collision, and something I think people would be better served to treat seriously instead of calling others names on the internet.

Re:Async Rust is not safe with io_uring by skavi on Sunday November 03, 2024 @10:52PM (#42038273)
Hi, I’m also from a systems programming background.

I’m not sure what your level of experience with Rust’s async model is, but an important thing to note is that work is split between an executor and the Future itself. Executors are not “special” in any way. In fact, the Rust standard library doesn’t even provide an executor.

Futures in Rust rely on their executors to do anything nontrivial. That includes the actual interaction with the io-uring api in this case.

A properly implemented executor really should handle cases where a Future decides to cancel its interest in an event.

Executors are themselves not implemented with async code [0]. So I’m not quite able to understand your claim of a paradigm mismatch.

[0]: subexecutors like FuturesUnordered notwithstanding.

Re:Async Rust is not safe with io_uring by skavi on Sunday November 03, 2024 @11:05PM (#42038338)
https://news.ycombinator.com/item?id=41996976

See this comment describing how an executor can properly handle cancelations.