Skip to content

Commit

Permalink
example: check client fd leak
Browse files Browse the repository at this point in the history
check client fd leak

Fixes: #255
Signed-off-by: Quanwei Zhou <[email protected]>
  • Loading branch information
quanweiZhou authored and quanwei.zqw committed Oct 8, 2024
1 parent ffc8735 commit 0fe539d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions example/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,36 @@ use ttrpc::error::Error;
use ttrpc::proto::Code;
use ttrpc::Client;

#[cfg(target_os = "macos")]
fn get_fd_count() -> usize {
// currently not support get fd count
0
}

#[cfg(not(target_os = "macos"))]
fn get_fd_count() -> usize {
let path = "/proc/self/fd";
let count = std::fs::read_dir(path).unwrap().count();
println!("get fd count {}", count);
count
}

fn main() {
connect_once();
let expected_fd_count = get_fd_count();

// connect 3 times and check the fd leak.
for index in 0..3 {
connect_once();
let current_fd_count = get_fd_count();
assert_eq!(
expected_fd_count, current_fd_count,
"check fd count in {index}"
);
}
}

fn connect_once() {
simple_logging::log_to_stderr(LevelFilter::Trace);

let c = Client::connect(utils::SOCK_ADDR).unwrap();
Expand Down

0 comments on commit 0fe539d

Please sign in to comment.