Skip to content
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

Fix bug: Async client may not close #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/asynchronous/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct Client {
req_tx: MessageSender,
next_stream_id: Arc<AtomicU32>,
streams: Arc<Mutex<HashMap<u32, ResultSender>>>,
_client_close: Arc<ClientClose>,
}

impl Client {
Expand All @@ -45,6 +46,7 @@ impl Client {
pub fn new(fd: RawFd) -> Client {
let stream = utils::new_unix_stream_from_raw_fd(fd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fd will be closed when ClientClose dropping

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, It looks like async client didn't hold ClientClose? If I miss?


let client_close = Arc::new(ClientClose{fd});
let (req_tx, rx): (MessageSender, MessageReceiver) = mpsc::channel(100);

let req_map = Arc::new(Mutex::new(HashMap::new()));
Expand All @@ -60,6 +62,7 @@ impl Client {
req_tx,
next_stream_id: Arc::new(AtomicU32::new(1)),
streams: req_map,
_client_close: client_close
}
}

Expand Down Expand Up @@ -157,12 +160,10 @@ impl Client {

struct ClientClose {
fd: RawFd,
close_fd: RawFd,
}

impl Drop for ClientClose {
fn drop(&mut self) {
close(self.close_fd).unwrap();
close(self.fd).unwrap();
trace!("All client is droped");
}
Expand Down
Loading