Skip to content

Commit

Permalink
os/unix/stream: stop into_raw_fd from closing the fd
Browse files Browse the repository at this point in the history
`UnixStream::into_raw_fd` calls `as_raw_fd`, which doesn't take the
ownership of the file descriptor, so the file descriptor is closed when
`self` is dropped upon returning from the function.

Because `UnixStream` uses a `Arc` to support Clone, there could be an
arbitrary number of instances around. We cannot take ownership of the
descriptor from all of the instances. Therefore we have no choice but to
duplicate the file descriptor and return that.

Fixes #855

Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Aug 18, 2020
1 parent 59874d6 commit b0ac73c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview

## [Unreleased]

## Fixed

- Ensure `UnixStream::into_raw_fd` doesn't close the file descriptor ([#855](https://github.com/async-rs/async-std/issues/855))

# [1.6.3] - 2020-07-31

## Added
Expand Down
2 changes: 1 addition & 1 deletion src/os/unix/net/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,6 @@ impl FromRawFd for UnixStream {

impl IntoRawFd for UnixStream {
fn into_raw_fd(self) -> RawFd {
self.as_raw_fd()
(*self.watcher).get_ref().try_clone().unwrap().into_raw_fd()
}
}

0 comments on commit b0ac73c

Please sign in to comment.