Skip to content

persist: retry transient errors instead of dropping blueprint - #66

Open
aradanmn wants to merge 1 commit into
KarsMulder:mainfrom
aradanmn:fix/persist-reopen-transient-error-retry
Open

aradanmn wants to merge 1 commit into
KarsMulder:mainfrom
aradanmn:fix/persist-reopen-transient-error-retry

Conversation

@aradanmn

Copy link
Copy Markdown

Hi Kars,

While using evsieve's persistence feature on a Steam Deck (SteamOS) to
merge a Bluetooth gamepad's input with other devices, I ran into a bug
where forwarding from the pad permanently stops after a Bluetooth
disconnect/reconnect cycle, even though evsieve itself and its virtual
output device keep running fine.

Root cause

When the Bluetooth pad reconnects, the kernel creates the new
/dev/input/eventN node before udev has had a chance to run and apply
the uaccess ACL that grants the logged-in user (and therefore
evsieve) permission to open it. For a short window — in my testing,
roughly 1 second — the node exists but is owned by root, so opening it
fails with EACCES.

Daemon::try_open() in src/persist/subsystem.rs treats any
TryOpenBlueprintResult::Error as terminal: the very first failed
open moves the blueprint straight into broken_blueprints, which
reports Report::BlueprintDropped and permanently stops evsieve from
ever trying to reopen that device again. Since this happens on the
very first EACCES — before udev has finished settling — a perfectly
healthy, about-to-be-usable device gets permanently dropped.

Observed log sequence (with a build that added extra tracing)

<pad disconnects>
persist: error reopening blueprint: EACCES ...   (attempt 1)
persist: error reopening blueprint: EACCES ...   (attempt 2)
persist: error reopening blueprint: EACCES ...   (attempt 3)
persist: error reopening blueprint: EACCES ...   (attempt 4)
persist: error reopening blueprint: EACCES ...   (attempt 5)
<~1s later, udev applies the uaccess ACL>
<pad reconnects successfully, forwarding resumes>

Without the fix, the very first EACCES in that sequence would have
dropped the blueprint and forwarding for that device would never come
back for the rest of the process's life.

I also confirmed that the pre-existing "capabilities differ on
reconnect" handling in Blueprint::try_open() (the warning path when
input_device.capabilities() != self.capabilities) is unaffected and
continues to work as designed — this fix only touches the
error-handling branch, not the success path.

Fix

Added an error_retries counter on Blueprint, incremented each time
try_open() returns Error. Instead of moving the blueprint to
broken_blueprints on the first error, Daemon::try_open() now
treats it similarly to NotOpened (i.e. retry later) until the
counter exceeds a bound (MAX_ERROR_RETRIES), at which point the
blueprint is dropped exactly as before. This preserves the existing
behavior for devices that are genuinely gone/broken, while giving
transient permission races during udev settling a chance to resolve
themselves.

I picked a fairly generous bound since the retry loop is cheap and
only runs when inotify tells us the device path changed; happy to
adjust the constant, use a time-based bound instead of a count-based
one, or take a different approach entirely if you'd prefer — I mostly
wanted to get the underlying bug and the reproduction context in front
of you. I'm also glad to add a test or CHANGELOG entry if that's
useful, just let me know your conventions.

Testing

  • Verified the failure and the fix by hand on a Steam Deck (SteamOS),
    triggering repeated Bluetooth gamepad disconnect/reconnect cycles.
    Without the fix, the first reconnect after evsieve started
    permanently killed forwarding for that pad. With the fix, evsieve
    recovers automatically each time, typically within about a second
    and 5-6 failed open attempts.
  • No automated test suite is included in this repo as far as I could
    tell; happy to add one if you point me at the right harness/pattern.

Thanks for evsieve, it's been very useful for this setup.

On some systems, a freshly (re)created input device node is briefly
owned by root before udev applies the appropriate uaccess ACL. This
was observed with Bluetooth gamepads on Steam Deck / SteamOS: when
the pad reconnects, the kernel creates /dev/input/eventN root-only
for a short window (roughly 1 second, 5-6 failed opens) while udev
settles, before ownership/permissions are updated.

Daemon::try_open() previously treated any TryOpenBlueprintResult::Error
as terminal: the very first failed open (e.g. EACCES during that
window) moved the blueprint straight to broken_blueprints, permanently
ending persistence for that device. The evsieve process and its
virtual output device kept running, but the physical device would
never be reopened even though it was actually available moments
later, effectively killing forwarding for the rest of the session.

Add an error_retries counter to Blueprint, incremented each time
try_open() reports an Error. Instead of giving up immediately, keep
retrying (like NotOpened) until the counter exceeds MAX_ERROR_RETRIES,
at which point the blueprint is finally dropped as before, preserving
the existing Report::BlueprintDropped semantics for devices that are
genuinely gone. This only changes when a blueprint is given up on; it
does not change how it is opened, and does not affect the case where
the reconnected device has different capabilities, which already
worked as designed.
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.

1 participant