Skip to content

fix(agent): survive EINTR and read the E2 socket level-triggered - #15

Draft
Thecave3 wants to merge 2 commits into
duranta-project:devfrom
Thecave3:agent-asio-epoll-fixes
Draft

Thecave3 wants to merge 2 commits into
duranta-project:devfrom
Thecave3:agent-asio-epoll-fixes

Conversation

@Thecave3

Copy link
Copy Markdown
Collaborator

Two independent fixes to the E2 agent's epoll loop (src/agent/asio_agent.c), one commit each.

1. A signal aborts the RAN process

event_asio_agent() asserts on any epoll_wait() error, EINTR included. EINTR is not an error: any signal delivered to the process interrupts the call, so attaching a debugger or a profiler to a running node is enough:

epoll_wait() returned -1: errno 4, Interrupted system call
asio_agent.c:134: event_asio_agent: Assertion `0' failed.

EINTR is now treated as an idle tick: the function returns -1, which is already what it returns when the wait times out with no events, so the caller polls again. Genuine errors still assert.

2. A message can sit unread in the E2 socket

The agent registers the E2 SCTP socket edge-triggered (EPOLLET), and the event loop reads one message per wakeup (e2ap_recv_msg_agent() once per SCTP_MSG_ARRIVED_EVENT). When two messages arrive together, the first wakeup reads one and the second stays in the socket buffer. No new arrival means no new edge, so the agent is not woken for it until a later message comes in, and the backlog never drains: each message is handled only when a later one arrives.

The E2 socket is now registered level-triggered through a new add_fd_level_asio_agent(), so the agent is woken again while unread messages remain. The internal pipe and the timers stay edge-triggered.

Tests

test/asio_agent/ is new, one test per commit, both #undef NDEBUG so they check in Release as well.

  • test_asio_eintr interrupts the wait with SIGALRM after 100 ms. On the unpatched code it aborts with the assertion above (exit 134).
  • test_asio_level_triggered leaves a datagram unread on a socket pair (it keeps message boundaries like SCTP) and expects a second wakeup. Registered edge-triggered, it fails at the second wakeup.

Built and tested on all three CI combinations (E2AP_V1/KPM_V2_01, E2AP_V2/KPM_V2_03, E2AP_V3/KPM_V3_00). On E2AP_V3 the full tree builds and ctest passes 14/14 apart from Unit_test_Agent_RIC_xApp and Unit_test_nearRT_RIC, which abort identically on dev at plugin_ric.c:187. On E2AP_V1 and E2AP_V2 the agent library and the two new tests were built and run.

@sgarg00 sgarg00 added ci-build-test Run the build and test suites for this pull request. retrigger-ci Re-run CI labels Oct 15, 2026
@github-actions github-actions Bot removed the retrigger-ci Re-run CI label Oct 15, 2026
@durantabot

Copy link
Copy Markdown
Collaborator

CI Build: #45 | Passed

@Thecave3
Thecave3 force-pushed the agent-asio-epoll-fixes branch from 39e7b65 to 4e25b54 Compare November 2, 2026 23:26
@durantabot

Copy link
Copy Markdown
Collaborator

CI Build: #78 | Passed

@Thecave3
Thecave3 marked this pull request as draft November 17, 2026 15:56
melkael and others added 2 commits November 26, 2026 08:38
event_asio_agent() asserted on any epoll_wait() error, EINTR included.
EINTR is not an error: any signal delivered to the process interrupts the
call, and attaching a debugger or a profiler to a running gNB guarantees it.
`gdb -p <gnb pid>` aborts the whole RAN process:

    epoll_wait() returned -1: errno 4, Interrupted system call
    asio_agent.c:134: event_asio_agent: Assertion `0' failed.

Treat EINTR as an idle tick and return -1, which is already what the function
returns when the wait times out with no events, so the caller polls again.
Genuine errors still assert.

test/asio_agent/ interrupts the wait with SIGALRM and aborts on the unpatched
code.

Co-authored-by: Andrea Lacava <thecave003@gmail.com>
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Andrea Lacava <thecave003@gmail.com>
The agent wakes on the E2 SCTP socket edge-triggered (EPOLLET) and reads one
message per wakeup. When two messages arrive together, the second stays in
the socket buffer until a later message arrives, and the backlog never
drains: each control is applied only when later ones come in.

Register the E2 socket level-triggered, so the agent is woken again while
unread messages remain. The internal pipe and the timers stay edge-triggered,
their leftover tokens are never read.

test/asio_agent/ leaves a message unread and expects a second wakeup, which
the edge-triggered registration never delivers.

Co-authored-by: Andrea Lacava <thecave003@gmail.com>
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Andrea Lacava <thecave003@gmail.com>
@Thecave3 Thecave3 removed the ci-build-test Run the build and test suites for this pull request. label Nov 27, 2026
@Thecave3
Thecave3 force-pushed the agent-asio-epoll-fixes branch from 4e25b54 to 28c220f Compare November 27, 2026 13:58

This branch has not been deployed

No deployments
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.

5 participants