Skip to content

Commit b0ac73c

Browse files
committedAug 18, 2020
os/unix/stream: stop into_raw_fd from closing the fd
`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]>
1 parent 59874d6 commit b0ac73c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://book.async.rs/overview
77

88
## [Unreleased]
99

10+
## Fixed
11+
12+
- Ensure `UnixStream::into_raw_fd` doesn't close the file descriptor ([#855](https://github.com/async-rs/async-std/issues/855))
13+
1014
# [1.6.3] - 2020-07-31
1115

1216
## Added

‎src/os/unix/net/stream.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,6 @@ impl FromRawFd for UnixStream {
252252

253253
impl IntoRawFd for UnixStream {
254254
fn into_raw_fd(self) -> RawFd {
255-
self.as_raw_fd()
255+
(*self.watcher).get_ref().try_clone().unwrap().into_raw_fd()
256256
}
257257
}

0 commit comments

Comments
 (0)
Please sign in to comment.