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

paste::get_contents leaks file descriptors to unix pipes #12

Open
e00E opened this issue Jun 21, 2020 · 11 comments
Open

paste::get_contents leaks file descriptors to unix pipes #12

e00E opened this issue Jun 21, 2020 · 11 comments
Labels
bug Something isn't working not wl-clipboard-rs

Comments

@e00E
Copy link

e00E commented Jun 21, 2020

sway version 1.4
[package]
name = "clipboard"
version = "0.1.0"
edition = "2018"

[dependencies]
wl-clipboard-rs = "0.4"
use wl_clipboard_rs::paste::{get_contents, ClipboardType, MimeType, Seat};

fn main() {
    let mut i: u64 = 0;
    loop {
        println!("iteration {}", i);
        // Sometimes the program hangs here forever after exhausting file descriptors.
        let result = get_contents(ClipboardType::Regular, Seat::Unspecified, MimeType::Text);
        if let Err(err) = result {
            println!("first error: {}", err);
            // Sleep so that we have time to inspect number of file descriptors.
            std::thread::sleep(std::time::Duration::from_secs(10));
            return;
        }
        i += 1;
    }
}
cargo build && target/debug/clipboard

On my machine I usually see output like:

...
iteration 454
[wayland-client] Protocol error 1 on object wl_display@1: invalid arguments for [email protected]
first error: Wayland compositor communication error

When this happens I check the open file descriptors (the binary is called clipboard):

lsof -p `pidof clipboard`
COMMAND      PID USER   FD   TYPE             DEVICE SIZE/OFF     NODE NAME
...
clipboard 265393    user  457u  unix 0x0000000066c7d124      0t0  9900913 type=STREAM

This number is going to depend on your system's file descriptor limit.

As mentioned in the comment, sometimes get_contents hangs forever instead. If you remove the return in the error branch and continue calling get_contents more errors will happen and get_contents will eventually hang.

@YaLTeR YaLTeR added the bug Something isn't working label Jun 21, 2020
@YaLTeR
Copy link
Owner

YaLTeR commented Jun 22, 2020

Thanks for the detailed report!

I think I need to finish updating to the newest wayland-rs before I investigate this. I should have most of the update done in the wayland-rs-master branch.

@YaLTeR
Copy link
Owner

YaLTeR commented Aug 31, 2020

I've updated wayland-rs, do you mind re-testing on latest master in case it was an old wayland-rs issue?

@e00E
Copy link
Author

e00E commented Aug 31, 2020

Still happens

@YaLTeR
Copy link
Owner

YaLTeR commented Feb 16, 2021

I investigated, looks like it's Smithay/wayland-rs#235 again. Using the native_lib feature makes the issue go away.

@YaLTeR
Copy link
Owner

YaLTeR commented Feb 16, 2021

Upon bringing it up with the wayland-rs maintainer, looks like the issue isn't that, but runs a bit deeper: Smithay/wayland-rs#376

@YaLTeR
Copy link
Owner

YaLTeR commented Feb 16, 2021

A possible workaround is to have a long-lived connection in wl-clipboard-rs instead of creating a new one every time, while making sure to destroy all objects when they are no longer needed.

@dnut
Copy link
Contributor

dnut commented Feb 23, 2022

I'm seeing the same problem in the latest version of wl-clipboard-rs. Looks like the issue is fixed in wayland-rs. Should we upgrade to wayland-client 0.29?

@YaLTeR
Copy link
Owner

YaLTeR commented Feb 24, 2022

I think it's only supposed to be fixed in wayland-client 0.30, which is the "full rework of the crate and API" version and AFAICT is not released yet.

@YaLTeR
Copy link
Owner

YaLTeR commented Jun 23, 2023

I've just finished porting to wayland-rs 0.30. Could you check if this is still an issue with the latest git commit?

@dnut
Copy link
Contributor

dnut commented Jun 26, 2023

I see EMFILE panics many times per day, which I believe is caused by this. I'll test this over the next few days and share my results.

@YaLTeR
Copy link
Owner

YaLTeR commented Jul 24, 2023

Hey, so how'd it go?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not wl-clipboard-rs
Projects
None yet
Development

No branches or pull requests

3 participants