Currently VsockListener and VsockStream have automatically derived impls of Clone, but since they contain only a RawFd (which is an alias for c_int, not an owned file descriptor), the clone implementation will "clone" the file descriptor by simply copying the integer. This will result in two streams/listeners containing the same file descriptor, so whichever one is dropped first will close() that fd, and the other will have a dangling fd which won't work anymore (or could even refer to a newly-opened file from elsewhere in the program).
Probably the correct thing to do is to just remove the #[derive(Clone)] and replace the try_clone() implementation with one that actually duplicates the file descriptor (e.g. dup() or fcntl(F_DUPFD_CLOEXEC)).
Alternatively, maybe it would be better to use OwnedFd instead of RawFd and use its try_clone() implementation, although that would bump the minimum Rust version to 1.63.0.
Currently
VsockListener
andVsockStream
have automatically derived impls ofClone
, but since they contain only aRawFd
(which is an alias forc_int
, not an owned file descriptor), the clone implementation will "clone" the file descriptor by simply copying the integer. This will result in two streams/listeners containing the same file descriptor, so whichever one is dropped first willclose()
that fd, and the other will have a dangling fd which won't work anymore (or could even refer to a newly-opened file from elsewhere in the program).Probably the correct thing to do is to just remove the
#[derive(Clone)]
and replace thetry_clone()
implementation with one that actually duplicates the file descriptor (e.g.dup()
orfcntl(F_DUPFD_CLOEXEC)
).Alternatively, maybe it would be better to use
OwnedFd
instead ofRawFd
and use itstry_clone()
implementation, although that would bump the minimum Rust version to 1.63.0.