Skip to content

Fix EINTR not handled in LineRequest.WaitEdgeEventsRespectfully - #2599

Open
karen-meyerzuhartlage-AP wants to merge 1 commit into
dotnet:mainfrom
karen-meyerzuhartlage-AP:fix/libgpiodv2-eintr-epoll-wait
Open

Fix EINTR not handled in LineRequest.WaitEdgeEventsRespectfully#2599
karen-meyerzuhartlage-AP wants to merge 1 commit into
dotnet:mainfrom
karen-meyerzuhartlage-AP:fix/libgpiodv2-eintr-epoll-wait

Conversation

@karen-meyerzuhartlage-AP

@karen-meyerzuhartlage-AP karen-meyerzuhartlage-AP commented Aug 18, 2026

Copy link
Copy Markdown

Fixes #2598

Related to #1210

LineRequest.WaitEdgeEventsRespectfully (used by LibGpiodV2Driver) calls Interop.epoll_wait without handling EINTR (errno 4). If the call is interrupted by a signal — which happens when a device resumes from standby/suspend — the method throws a GpiodException instead of retrying.

The V1 LibGpiodDriverEventHandler already ignores Interrupted system call error and continues waiting for events (see #1210). This PR implements the same behaviour for LibGpiodV2Driver.

Microsoft Reviewers: Open in CodeFlow

@dotnet-policy-service dotnet-policy-service Bot added the area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins label Aug 18, 2026
@karen-meyerzuhartlage-AP

Copy link
Copy Markdown
Author

@karen-meyerzuhartlage-AP please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree company="Anton Paar OptoTec GmbH"

@raffaeler

Copy link
Copy Markdown
Contributor

[Triage] Code looks ok, but we require a hardware test before approving. This may take some time.

@krwq
krwq requested a lite review from Copilot August 20, 2026 15:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a reliability issue in the libgpiod v2 GPIO edge-event waiting path by retrying epoll_wait when it fails with EINTR, matching the existing behavior in the libgpiod v1 event handler and preventing edge-event processing from stopping after suspend/resume.

Changes:

  • Add an EINTR retry loop around Interop.epoll_wait in LineRequest.WaitEdgeEventsRespectfully.
  • Introduce an ERROR_CODE_EINTR constant in the v2 LineRequest proxy to align with existing drivers’ interrupt-handling patterns.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +314 to 322
var errorCode = Marshal.GetLastWin32Error();

if (errorCode == ERROR_CODE_EINTR)
{
// ignore Interrupted system call error and retry
continue;
}

throw new GpiodException($"Error while waiting for edge events, epoll_wait: {LastErr.GetMsg()}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins

Projects

None yet

Development

Successfully merging this pull request may close these issues.

epoll_wait error with libgpiod2 after suspend/resume

3 participants