Repository navigation
Conversation
This was referenced Oct 15, 2026
Collaborator
Author
|
This PR is part of a stack and is open as a draft for visibility only; it is not ready for review yet. It is based on #22, so its diff also contains the commits of the PRs below it until those merge. The stack, bottom to top: #16, #18, #19, #20, #21, #22, #23, #24. Please review in that order; the commits specific to this PR are the last ones in the list. It will be rebased and marked ready for review once the PR below it has merged. |
This was referenced Oct 15, 2026
Thecave3
force-pushed
the
agent-survive-osc-e2-setup-failure
branch
from
October 28, 2026 16:05
30f194d to
dde5ba8
Compare
e2_async_event_agent() resolved the subscription an aperiodic indication
answers with eq_ind_event_ric_req_id, which compares ric_req_id only.
ag->ind_event is keyed on the full ric_gen_id_t and can hold several entries
sharing a RIC Requestor ID: E2AP identifies a subscription by
{RequestorID, InstanceID}, and the O-RAN SC near-RT RIC's subscription manager
sets one fixed Requestor ID on every subscription it sends (ricRequestorId =
123, pkg/control/control.go).
First match wins, and cmp_ric_gen_id orders ran_func_id descending, so the
highest-numbered RAN function under that Requestor ID captures every aperiodic
indication. Its service model is then handed another model's ind_data, decodes
a foreign struct and aborts the RAN process.
Carry ric_gen_id_t end to end (sm_subs_data_t, wr_rc_sub_data_t, the async API,
free_aper_subs) and match on it with the existing eq_ind_event. Delete
eq_ind_event_ric_req_id, which has no correct use.
The aperiodic fd had the same defect. It was derived as -ric_req_id, so two
subscriptions sharing a Requestor ID collide on the bi_map key, and Requestor
ID 0 yields fd 0, which stop_ind_event() reads back as a real fd. Count down
from -1 instead.
An indication for a subscription that was just deleted is a race the RAN can
lose legitimately, so log and drop it instead of asserting.
It is dormant with FlexRIC's own near-RT RIC, which allocates a new Requestor
ID per subscription.
test/aperiodic_routing/ routes three subscriptions under one Requestor ID and
fails on the Requestor-ID-only matching.
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Andrea Lacava <thecave003@gmail.com>
ag->ind_event is a multiset: assoc_rb_tree_insert does not reject equality and cmp_ind_event compared RIC IDs only, so two subscriptions can sit under one ric_gen_id_t. A near-RT RIC produces that by installing a subscription the agent still holds, or by reusing one Requestor ID, as the O-RAN SC one does. A delete then corrupted the registry. stop_ind_event() found its entry with a linear scan (find_if_rb_tree) but unlinked with a binary search on the same ambiguous key (bi_map_extract_right), and those are not the same node. One entry's act_def was freed while another was unlinked, so the survivor kept an armed timer and a freed act_def, which the next tick handed to the service model. The fd already identifies a subscription: a timerfd when periodic, a negative synthetic one when aperiodic. Record it in ind_event_t, break ties on it in cmp_ind_event so the tree is a total order, and extract by it with bi_map_extract_left. eq_ind_event still matches on the RIC ID alone, which is what lets e2_async_event_agent() find a subscription without knowing its fd. test/ind_event_key/ installs three subscriptions under one RIC ID and deletes them; on the previous keying one act_def is freed twice. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
A second E2 SETUP RESPONSE aborts the RAN process:
assoc_rb_tree.c:457: assoc_rb_tree_extract: Assertion `z_node !=
tree->dummy && "Trying to extract a key not found in the tree"' failed.
stop_pending_event() calls bi_map_extract_right(), which asserts that the key
is present. The first response removes the pending timer entry; a second one
tries to remove it again and aborts. A second assert sits right behind it,
since the first response zeroes trans_id_setup_req. Both assert on what a peer
sent rather than on an internal invariant, so a RIC that answers a setup twice
takes down the RAN.
stop_pending_event() now probes before extracting and reports whether it found
anything, and the handler ignores the message when no request is outstanding.
The probe mirrors stop_ind_event(), which has always checked it_r != end_r.
The transaction ids are still reported and not compared: not every RIC echoes
the id it was sent, and rejecting the mismatch would drop the only response
such a peer sends.
test/agent/ reproduces the abort on the unpatched handler. Built and tested
for E2AP_V1/KPM_V2_01, E2AP_V2/KPM_V2_03 and E2AP_V3/KPM_V3_00.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Andrea Lacava <thecave003@gmail.com>
(cherry picked from commit eebef0e)
Signed-off-by: Andrea Lacava <thecave003@gmail.com>
stop_ind_event() unlinked a subscription from both trees without holding ag->mtx_ind_event, although insert takes it and e2_async_event_agent() traverses the right tree under it from the RAN threads. A delete could free a node while one of them was walking it. Split it into unlink_ind_event(), which holds the mutex while it unlinks, and release_ind_event(), which stops the producer and hands the payload back with the mutex released, since free_act_def and free_subs_aperiodic are service model and RAN code. The producer is now stopped before its payload is released, not after. No other change in behavior. This is groundwork to drop every subscription at once. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
On SCTP_SHUTDOWN_EVENT the agent only armed the E2 SETUP REQUEST retry. Every installed subscription kept its timer and its action definition, so the agent went on producing indications for a RIC that had forgotten them, and the RAN's own registry kept the aperiodic ones, since free_subs_aperiodic() is only reachable from the delete path. E2AP keeps no subscription state across an association. stop_all_ind_events() now drops every subscription before the retry is armed. The teardown is gated on SCTP_SHUTDOWN_EVENT: every SCTP notification reaches notification_handle_ag(), and cp_sctp_notification() already decodes SCTP_COMM_UP, which must not tear anything down. The retry is also armed only when none is pending, since pend_event() asserts that the map holds exactly one entry and a second notification before the E2 SETUP RESPONSE would abort the RAN on the next timer tick. test_association_loss fails without the change. Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
notification_handle_ag() ended the E2 session on SCTP_SHUTDOWN_EVENT alone, and the agent did not subscribe to association events, so a SHUTDOWN was the only notification that could arrive. A nearRT-RIC that goes away without one (its host or the network fails, or it sends an ABORT) or that comes back under the same addresses produces no SHUTDOWN: the kernel reports SCTP_COMM_LOST or SCTP_RESTART, and only to a socket that asked for association events. Neither was seen, so subscriptions stayed installed and no E2 SETUP REQUEST was sent again. The socket is one-to-many, so the next indication silently opened a new association to a restarted RIC with no E2 setup on it. Subscribe to association events, and end the session on SCTP_COMM_LOST and SCTP_RESTART as on SCTP_SHUTDOWN_EVENT. SCTP_COMM_UP, SCTP_CANT_STR_ASSOC and SCTP_SHUTDOWN_COMP are not an end and stay ignored. No other event type is subscribed, since cp_sctp_notification() asserts on the ones it does not decode. test_association_loss covers the six association outcomes and fails without the change. Co-authored-by: Andrea Lacava <thecave003@gmail.com> Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
After an association ends, aperiodic indications queued before the end, or racing it, are still drained and sent. The send does not fail: the socket is one-to-many, so sctp_sendmsg() to the RIC's address silently opens a new association and delivers the message on it, to a restarted nearRT-RIC that has seen no E2 SETUP from this node and ahead of the E2 SETUP REQUEST the retry timer is about to send. Track the session in e2_session_up, set by an accepted E2 SETUP RESPONSE and cleared first thing when the session ends. While it is down, the aperiodic indication drain releases what it holds and sends nothing, and e2_send_indication_agent() returns. Answers to a RIC message need no check, since they go back on the association the message came in on. Making the response the start of the session exposes an ordering bug in e2ap_handle_setup_response_agent() (E2AP v2/v3), which stopped the retry timer before checking that a request was outstanding. After a loss the retry is armed but sends nothing until it fires; a response landing in that window stopped the timer and was then ignored, which left the agent with no E2 SETUP REQUEST to send. The transaction id check now comes first. test_setup_response and test_association_loss check the session flag on every path, that a response before the retry fires keeps the retry, and that an indication outside a session is dropped. Co-authored-by: Andrea Lacava <thecave003@gmail.com> Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
The v2.03 encoders and decoders for RESET REQUEST and RESET RESPONSE, and the v3.01 decoders, open with assert(0!=0 && "Untested code"), and the round-trip tests for them are commented out. FlexRIC is built in Debug by default, so an E2 node that receives a RESET REQUEST aborts in e2ap_dec_reset_request() before any handler sees the message. The encoders were wrong as well. From E2AP v2 on, TransactionID is mandatory in both messages and the decoders read it first, but neither encoder wrote it: a RESET RESPONSE carried no IE at all, and decoding one read past an empty IE list. Write the TransactionID first in both encoders, drop the guards, and have the decoders check the IE count before they read the mandatory IEs by index. The round-trip tests run again, with a non-zero transaction id. v1.01 has no TransactionID and is unchanged. Co-authored-by: Andrea Lacava <thecave003@gmail.com> Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
e2ap_handle_reset_request_agent() and e2ap_handle_reset_response_agent() are assert(0) stubs, and the dispatch table routes both messages to them. With the E2AP codec decoding the two messages, a nearRT-RIC that resets its E2 nodes, to recover its own state without dropping the association, would still take the RAN down here. A RESET undoes what E2 procedures installed since the E2 SETUP and keeps the E2 setup itself. Drop every RIC subscription through stop_all_ind_events() and answer with a RESET RESPONSE that echoes the transaction id. The E2 session stays up and no E2 SETUP REQUEST is armed. This node never sends a RESET REQUEST, so a RESET RESPONSE answers nothing: it is logged and ignored. test_reset checks both handlers, and puts the answer through the agent's encoder and decoder. Co-authored-by: Andrea Lacava <thecave003@gmail.com> Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
The O-RAN SC RIC answers an E2 SETUP REQUEST it cannot take yet with an E2 SETUP FAILURE: Cause misc / control-processing-overload, TimeToWait v60s, and a TransactionID IE whose criticality is ignore. A node that reconnects soon after a loss gets it, and the agent aborted on it twice: - e2ap_dec_setup_failure() (v2 and v3) asserted criticality reject on the TransactionID; - e2ap_handle_setup_failure_agent() asserted cause.present < 6 and indexed a table of E2AP v1 cause kinds, but E2AP v2 inserted e2Node before transport, so misc is 6. Accept either criticality on that IE, and have the handler log the cause through a version-aware switch instead of a table, asserting nothing about it. The retry timer keeps running, so the request goes out again within 3 s. TimeToWait is logged but not honoured. test_setup_failure puts that message through the agent's decoder and handler, and checks that the retry is kept. It is built for E2AP v2 and v3, which have the generated ASN.1 types it needs. Co-authored-by: Andrea Lacava <thecave003@gmail.com> Assisted-by: Claude:claude-sonnet-5-5 Signed-off-by: Andrea Lacava <thecave003@gmail.com>
Thecave3
force-pushed
the
agent-survive-osc-e2-setup-failure
branch
from
November 27, 2026 13:59
dde5ba8 to
ba47be9
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The O-RAN SC RIC answers an E2 SETUP REQUEST it cannot take yet with an E2 SETUP FAILURE: Cause misc / control-processing-overload, TimeToWait v60s, and a TransactionID IE whose criticality is
ignore. A node that reconnects soon after a loss gets it, and the agent aborts on it twice over:e2ap_dec_setup_failure()(v2 and v3) asserts criticalityrejecton the TransactionID;e2ap_handle_setup_failure_agent()assertscause.present < 6and indexes a table of E2AP v1 cause kinds, but E2AP v2 insertede2Nodebeforetransport, somiscis 6.The change
The decoders accept either criticality on that IE. The handler logs the cause through a version-aware switch instead of a table and asserts nothing about it, since everything in it comes from the RIC. The retry timer keeps running, so the request goes out again within 3 s. TimeToWait is logged but not honoured, so that a RIC that accepts the node again sooner is not kept waiting.
Tests
test/agent/test_setup_failure.cis new. It takes that message in XER, encodes it to APER as it arrives on the wire, and puts it through the agent's decoder and handler, then checks that the retry is kept. It is built for E2AP v2 and v3, the versions that have the generated ASN.1 types it needs. Ondevit aborts on the criticality assert.Verification
Full build and
ctest(excludingUnit_test_Agent_RIC_xAppandUnit_test_nearRT_RIC) at the tip of this branch, Debug:E2AP_V3/KPM_V3_00E2AP_V2/KPM_V2_03E2AP_V1/KPM_V2_01test_setup_failurewas checked to abort without the change onE2AP_V3(on the decoder assert; the handler's cause-table assert was not exercised on its own). The handler change touches code compiled for E2AP v1 (cause_kind()/cause_value()guardCAUSE_E2NODE); that compilation is unverified.