Comments (2)
The epoll::add
function takes an source: impl AsFd
. When you pass a Timer
, it behaves as if the argument were source: Timer
, meaning the function assumes ownership of the Timer
. add
drops source
when it returns, which closes the fd. When you pass &Timer
, which by the use of this rule also implements AsFd
, it behaves as if the argument were source: &Timer
, so when it drops source
, it doesn't close the fd.
This is a hazard we've known about since AsFd
was designed, but didn't think was a major practical problem, because usually when someone accidentally passes ownership when they didn't mean to, like this:
let file = openat(...)?;
let t = fstat(file)?; // oops, forgot to borrow
continue_to_use(file);
they get compilation errors, because file
is used after ownership is transferred away.
But with epoll
here, it is a real hazard, because you want to keep the fd open even if you never try to reference it through the owned fd you have.
Offhand, I'm not sure what we can do about this.
from rustix.
Thank you for your very clear explanation, it makes total sense. It seems that I've a hit a rare path where the compiler couldn't help me.
from rustix.
Related Issues (20)
- `u32` struct fields in place of file descriptors HOT 2
- Add signalfd support HOT 1
- Build failure for i686-unknown-hurd-gnu HOT 2
- Failed to build on LoongArch
- Support for HermitOS
- missing getifaddrs
- fsmount not returning fd correctly HOT 3
- I
- Docs are missing for some APIs HOT 3
- Add `mount_setattr`
- Panics when /proc is not available on i386 HOT 5
- Several compilation issues on uClibc targets in version 0.38.28. HOT 2
- Version 0.38.29 fails to build on Linux HOT 1
- Add ClockId::try_from
- waitpid doesn't returned pid HOT 4
- Build errors for i686-apple-darwin HOT 1
- Add support for pidfd_send_signal
- `proc_self_status` fails on second invocation HOT 1
- add io_uring_sqe64,io_uring_sqe128,io_uring_cqe16,io_uring_cqe32 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rustix.