cloudflare / cloudflare/boringtun

file descriptor leak

Open
#170 2 comments 1 reaction 1 assignee Claimed by @vkrasnov View on GitHub
bug
Dominant language
Rust
Stars
7.2k
Forks
532
PR merge metrics
No merged PRs in 30d

Description

Currently boringtun leaks file descriptors. If we add this to src/device/integration_tests/mod.rs:
```
#[test]
/// Test if wireguard leaks resources on closing
fn test_fd_leaks() {
let n_before = count_file_descriptors_currently_in_use();
let wg = WGHandle::init("192.0.2.0".parse().unwrap(), "::2".parse().unwrap());
let response = wg.wg_get();
assert!(response.ends_with("errno=0\n\n"));
drop(wg); // call destructor
let n_before = count_file_descriptors_currently_in_use();
assert_eq!(n_before, n_after);
}
```
This test will fail.
Comments:
- `count_file_descriptors_currently_in_use()` would count only file descriptors in use by the current process.
- The implementation for the `count_file_descriptors_currently_in_use()` method is platform-specific but a naive implementation for Linux would be

```
pub fn count_file_descriptors_currently_in_use() -> u16 {
use std::process;
use std::process::Command;
let path = format!("/proc/{}/fd/", process::id());
let output = Command::new("ls")
.args(&["-l", &path])
.output()
.expect("failed to get fd info");
let stdout = String::from_utf8_lossy(&output.stdout);
let mut n: u16 = 0;
for x in stdout.lines() {
n += 1;
}
n
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.