-
Notifications
You must be signed in to change notification settings - Fork 191
Remove the context API from epoll #487
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
Conversation
This is a pretty subtle situation. It's true that there's no use-after-free hazard, but there is a use-of-a-borrow-after-it-goes-out-of-scope hazard. And I'm not sure how to think about that yet. If some code does |
From a semantic point of view, I like to think of a file descriptor as an |
The equivalent of an Arc clone is a dup, but EPOLL_CTL_ADD isn't a dup, and I expect this is observable in various ways. For example, events will contain the file descriptors' numbers, so it's observable that they "escaped" the borrow without a dup. We may be able to do this, but I want to think through the consequences more. |
The events themselves actually don't contain the file descriptor; it's just the event number that was passed in to the event. (This may be an issue for |
Rustix's epoll API currently does store the file descriptor number in the epoll user data, and provides it to users as a file descriptor along with events. This way users that just need the file descriptor can get it, without having to keep a separate That said, I have been thinking about whether it's better to just letting users manage the |
I replaced |
4deda6d
to
2cd2e7c
Compare
@sunfishcode Is there any chance you can review this?
In my opinion, this abstraction is too high level for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, this abstraction is too high level for
rustix
. If users want to keep track of data associated with thedata
field, it should be their decision to do so.
I agree. I think this PR sounds like the right approach overall. The current Epoll abstraction was an attempt to provide an API that wouldn't require users to use unsafe, but it ended up getting too complex. This does appear to be a disadvantageous abstraction level for safety.
I'm still concerned about epoll holding onto file descriptors and reporting events for them after the scope of their borrow ends. There's no direct use-after-close hazard, but it seems error-prone. What would you think about making epoll_add
unsafe, having it take an AsRawFd
, and documentingbthat it behaves as if the raw fd is retained?
Also, tagging with 0.37, as this is a semver bump.
I don't think there's much danger here. The worst thing that can happen is a spurious event (which is pretty much expected to happen with leaky behavior like this anyways). I've added documentation to |
I started a thread about this in Zulip: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/I.2FO.20safety.20for.20epoll . @bjorn3 suggested thinking of epoll as doing a "weak dup", which I'm thinking makes sense. If you want to write some documentation along those lines feel free, though I'd be happy to do a follow-up PR myself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a rustfmt for.CI, and I notice one other simplification we can make now:
I added a mention of it to |
Sounds good! |
Use the new epoll API from bytecodealliance/rustix#487. Fixes #86.
It looks like we were overthinking it; from a brief glance at the documentation, it looks like deleting a file descriptor registered in
epoll
is not undefined behavior, at least by Rust's specifications. This PR removes theContext
API and just uses theBorrowedFd
API.Closes #477