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

grpcio::Env can leak threads -- it detaches them instead of joining them #455

Open
wants to merge 2 commits 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
18 changes: 10 additions & 8 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ impl Drop for Environment {
// it's safe to shutdown more than once.
cq.shutdown()
}

// Join our threads when we leave scope
// Try not to join the current thread
let current_thread_id = std::thread::current().id();
for handle in self._handles.drain(..) {
if handle.thread().id() != current_thread_id {
handle.join().unwrap();
}
}
}
}

Expand All @@ -146,7 +155,7 @@ mod tests {

#[test]
fn test_basic_loop() {
let mut env = Environment::new(2);
let env = Environment::new(2);

let q1 = env.pick_cq();
let q2 = env.pick_cq();
Expand All @@ -163,12 +172,5 @@ mod tests {
}

assert_eq!(env.completion_queues().len(), 2);
for cq in env.completion_queues() {
cq.shutdown();
}

for handle in env._handles.drain(..) {
handle.join().unwrap();
}
}
}