Skip to content

The AsyncFd in Tokio has a serious memory leak issue. #7563

@silence-coding

Description

@silence-coding

I'm not sure if the issue is with my usage, and I look forward to your help. Here is my reproduction code.
main.rs

use std::sync::Arc;
use std::time::Duration;
use tokio::io::unix::AsyncFd;

#[tokio::main]
async fn main() {
    loop {
        let fd = unsafe { libc::inotify_init1(libc::O_CLOEXEC | libc::O_NONBLOCK) };
        if fd == -1 {
            return;
        }
        let afd = Arc::new(fd);
        let async_fd = AsyncFd::new(afd.clone()).unwrap();
        unsafe {
            libc::close(fd);
        }
        tokio::time::sleep(Duration::from_millis(1)).await;
        drop(async_fd);
    }
}

Cargo.toml

[dependencies]
[package]
name = "testexamples"
version = "0.1.0"
edition = "2024"

[dependencies]
tokio = { version = "1.47.1", features = ["full"] }
libc = "0.2.174"

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-tokioArea: The main tokio crateC-bugCategory: This is a bug.M-ioModule: tokio/io

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions