ringbahn / ringbahn

safe bindings to io-uring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cancellation and file descriptors

withoutboats opened this issue · comments

User sintrowel on Reddit comments:

I may very easily be not considering something. However, with the existing Ringbahn interfaces I think its possible for an operation to get queued up for a particular file descriptor without being immediately submitted. Then, prior to being submitted, the future that submitted the operation is dropped, causing the file descriptor to be closed. However, the operation is still queued up, and, once it is actually submitted, will either act against an invalid file descriptor or end up acting on some other unrelated file. Is this possible, or is there a mechanism to prevent this that I did not see in the code?

I need to think about this more. With Event you're taking a raw FD, and its sort of your responsibility. But Ring should handle closing itself properly.

The problem is managing the lifecycle, because dropping the future representing a read/write is not the same as closing the FD. So you could cancel -> do more IO -> etc or you could cancel -> close. Ring probably needs to be more aware of the state of past IO interest that hasn't completed in some way.

Probably the way cancellation on Ring should work is that when you try to issue a new event on the FD Ring manages, if another event is underway, Ring issues a cancellation linked before the new event, so the ongoing event will be cancelled, then the new event will proceed, no matter what the two events are.

And the Event API will want to provide a manually implement this behavior as well.

@withoutboats That idea doesn't work for me - I'd like multiple independent operations working against the same fd (that is, multiple Rings operating against a single fd, along with Events and so on). io_uring's opcodes do not seek the file pointer internally afaict, so this should be easy from that perspective.

For my use case, I'd like to see Ring be able to take an Rc or Arc to an AsRawFd object, then drop it when the Ring is dropped + all in-flight requests in that Ring referencing it are completed. I have implemented a similar thing for a custom Event.

@VShell probably the ring state machine should be exposed as a low level interface you could use to build a shared ring construct.

Hopefully avoided by #47, but I never got feedback on axboe/liburing#147