Skip to content

Commit

Permalink
Fixed leaked sock states, issue tokio-rs#1146. A reference of the soc…
Browse files Browse the repository at this point in the history
…k state Arc is blocked by a pending afd poll request, this reference will leak if there's no explicit poll done before the program terminates. That's why

doing an explicit "select" during iner selector drop ensures all sock state references are freed.

Signed-off-by: Daniel Tacalau <dst4096@gmail.com>
  • Loading branch information
dtacalau committed Nov 23, 2019
1 parent 76b3b77 commit 4ba341e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/sys/windows/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@ pub struct SelectorInner {
// We have ensured thread safety by introducing lock manually.
unsafe impl Sync for SelectorInner {}

impl Drop for SelectorInner {
fn drop(&mut self) {
loop {
let mut events = Events::with_capacity(1024);
let _ = self.select(&mut events, Some(std::time::Duration::from_millis(0)));
if events.events.len() < 1024 {
break;
}
}

self.afd_group.release_unused_afd();
}
}

impl SelectorInner {
pub fn new() -> io::Result<SelectorInner> {
CompletionPort::new(0).map(|cp| {
Expand Down

0 comments on commit 4ba341e

Please sign in to comment.