Giter VIP home page Giter VIP logo

Comments (10)

jeandudey avatar jeandudey commented on August 24, 2024 1

I can reproduce it, I'll look into it, thanks for reporting

from tokio-udev.

sjoerdsimons avatar sjoerdsimons commented on August 24, 2024 1

@jeandudey Mind that there is already a tokio-udev 0.8 on crates.io for some reason ; So for a new relese you probably want to bump to version 0.9 :)

from tokio-udev.

ajanon avatar ajanon commented on August 24, 2024 1

This solves the issue on swhkd's end perfectly, thanks a lot!

@jeandudey Unless the original reporter still has issues, I think you can close this. Could you push a new release with the latest changes?

@CluelessTechnologist Thanks for pinging me on this! You can test it on the udev_async branch on swhkd if you want to!

from tokio-udev.

jeandudey avatar jeandudey commented on August 24, 2024

Do you have some example code? So I can reproduce and track it down. Thanks for reporting!

from tokio-udev.

ajanon avatar ajanon commented on August 24, 2024

Hi,

I think we faced the same issue (or a very similar one) in swhkd.
This was reported on our side in waycrate/swhkd#162.

The test setup is rather simple: run the code below and connect/disconnect an input device (a keyboard or a mouse should do). Notice how some events are delayed. This may take more than one connect/disconnect.

Here is the MWE from the above issue to make it easier to track here.

use std::error::Error;
use std::time::{SystemTime, UNIX_EPOCH};
use tokio::select;
use tokio_stream::StreamExt;
use tokio_udev::{AsyncMonitorSocket, MonitorBuilder};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut udev = AsyncMonitorSocket::new(MonitorBuilder::new()?.match_subsystem("input")?.listen()?)?;
    loop {
        select! {
            Some(Ok(event)) = udev.next() => {
                println!("[{:?}] '{:?}' event - devnode: {:?}",
                         SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs(),
                         event.event_type(),
                         event.devnode());
            }
        }
    }
}

For two disconnections/reconnections, this gives me (late events in bold):

[1663146903] 'Remove' event - devnode: Some("/dev/input/event3")
[1663146903] 'Remove' event - devnode: None
[1663146903] 'Remove' event - devnode: Some("/dev/input/event5")
[1663146903] 'Remove' event - devnode: None
[1663146903] 'Remove' event - devnode: Some("/dev/input/event6")
[1663146903] 'Remove' event - devnode: None
[1663146903] 'Remove' event - devnode: Some("/dev/input/event7")
[1663146903] 'Remove' event - devnode: Some("/dev/input/event8")
[1663146903] 'Remove' event - devnode: None
[1663146919] 'Remove' event - devnode: None
[1663146919] 'Add' event - devnode: None
[1663146919] 'Add' event - devnode: None
[1663146919] 'Add' event - devnode: None
[1663146919] 'Add' event - devnode: None
[1663146919] 'Add' event - devnode: None
[1663146919] 'Add' event - devnode: Some("/dev/input/event6")
[1663146919] 'Add' event - devnode: Some("/dev/input/event8")
[1663146919] 'Add' event - devnode: Some("/dev/input/event5")
[1663146919] 'Add' event - devnode: Some("/dev/input/event7")
[1663146925] 'Add' event - devnode: Some("/dev/input/event3")
[1663146925] 'Remove' event - devnode: Some("/dev/input/event3")
[1663146925] 'Remove' event - devnode: None
[1663146925] 'Remove' event - devnode: Some("/dev/input/event5")
[1663146925] 'Remove' event - devnode: None
[1663146925] 'Remove' event - devnode: Some("/dev/input/event6")
[1663146925] 'Remove' event - devnode: None
[1663146925] 'Remove' event - devnode: Some("/dev/input/event7")
[1663146925] 'Remove' event - devnode: None
[1663146925] 'Remove' event - devnode: Some("/dev/input/event8")
[1663146932] 'Remove' event - devnode: None
[1663146932] 'Add' event - devnode: None
[1663146932] 'Add' event - devnode: None
[1663146932] 'Add' event - devnode: None
[1663146932] 'Add' event - devnode: None
[1663146932] 'Add' event - devnode: None
[1663146932] 'Add' event - devnode: Some("/dev/input/event6")
[1663146932] 'Add' event - devnode: Some("/dev/input/event8")
[1663146932] 'Add' event - devnode: Some("/dev/input/event5")

Please note that here, the input which is the actual keyboard is /dev/input/event3 but it is passed to the application only after it has been removed again.

I do not understand why this happens. The most I was able to understand was that the stream sometimes got 'stuck' on Poll::Pending as if no new events were available (but there actually was).

Running udevadm monitor -s input at the same time shows events in real time with no lag.

Sample Cargo.toml used for this test:

[package]
name = "test_udev"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.23.0", features = ["full"] }
tokio-stream = "0.1.11"
tokio-udev = "0.8.0

from tokio-udev.

CluelessTechnologist avatar CluelessTechnologist commented on August 24, 2024

I've added a bounty to get this issue solved. Need it solved in order to fix another an issue in swhkd project.

from tokio-udev.

 avatar commented on August 24, 2024

from tokio-udev.

jeandudey avatar jeandudey commented on August 24, 2024

@CluelessTechnologist could you try reproducing on the recent master branch?

I've pushed @sjoerdsimons changes and it seems to be working as it essentially tries to drain the events before polling again which should be the right thing to do.

Let me know before pushing a 0.8 release.

from tokio-udev.

CluelessTechnologist avatar CluelessTechnologist commented on August 24, 2024

I'm just a user. I'm not competent enough in Rust to be able to test this. Sorry. But I asked in swhkd matrix channel if there was someone from the dev team that could take a look. I don't know if @ajanon is able to test again perhaps?

Many thanks for fixing it though! Appreciate it!

from tokio-udev.

jeandudey avatar jeandudey commented on August 24, 2024

I've released v0.9.0 on crates.io.

Will close this issue as it appears solved, if not please reopen and let me know what needs to be done/fixed. Thanks guys!

from tokio-udev.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.