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

Wait up to two seconds for input device to become available. #215

Merged
merged 1 commit into from
Apr 1, 2024

Conversation

KarsMulder
Copy link
Contributor

It has been reported in issue #214 that even on modern Linux distributions that use devtmpfs, it can take longer than 0.1 seconds before the input device becomes available with the right permissions.

To solve this: if sysfs reports that a specific input device should be used, but it cannot be opened immediately, keep trying again for up to two seconds.

This only adjusts the _find_device_linux function, because adding such a loop to _find_device_fallback runs at risk of causing issue #205 again on outdated operating systems: if the sought device is not readable yet, but another device with the same name already exists, then there is a risk that we open the other device with the same name instead of the intended one.

(Unless _find_device_fallback refuses to return a device if another device with a higher event number is still unreadable. But that goes another layer deeper into "I do not have the proper environment to test this", so I've refrained from implementing that.)

A sporadic error of "sometimes the wrong device is opened when the system is under heavy load" is even harder to debug than a sporadic error of "sometimes no device is opened at all when the system is under heavy load".

The function _find_device_linux does not risk returning the wrong device because sysfs can immediately tell us exactly which device we need, even if the that input device doesn't have the right permissions yet.

It has been reported that even on modern Linux distributions that use
devtmpfs, it can take longer than 0.1 seconds before the input device
becomes available with the right permissions. If sysfs reports that a
specific input device should be used, but it cannot be opened
immediately, keep trying again for up to two seconds.
@sezanzeb sezanzeb merged commit 5fb3190 into gvalkov:main Apr 1, 2024
6 checks passed
@sezanzeb
Copy link
Collaborator

sezanzeb commented Apr 1, 2024

Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants