fix(producer): guard against nil EventChannel in N1N2 handlers#663
Merged
gab-arrobo merged 2 commits intoApr 22, 2026
Merged
Conversation
gab-arrobo
force-pushed
the
fix/n1n2-nil-eventchannel-cm-idle
branch
from
April 20, 2026 15:41
1e12ced to
97801ab
Compare
There was a problem hiding this comment.
Pull request overview
This PR prevents AMF panics when N1N2 SBI requests arrive for a UE whose context was restored from DB and therefore has a nil AmfUe.EventChannel, by adding a direct-procedure fallback in the N1N2 HTTP handlers.
Changes:
- Add
ue.EventChannel == nilguards in the three N1N2 handlers. - When nil, bypass event-channel dispatch and invoke the underlying procedure directly, with WARN logging.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gab-arrobo
force-pushed
the
fix/n1n2-nil-eventchannel-cm-idle
branch
from
April 20, 2026 16:10
97801ab to
9b95b74
Compare
donivtech
pushed a commit
to donivtech/amf
that referenced
this pull request
Apr 22, 2026
The event-channel path in HandleN1N2MessageSubscirbeRequest declared and type-asserted msg.RespData to *UeN1N2InfoSubscriptionCreateData (the request type) while N1N2MessageSubscribeProcedure actually returns *UeN1N2InfoSubscriptionCreatedData (the response type). Per TS 29.518, a successful subscribe returns UeN1N2InfoSubscriptionCreatedData with the allocated subscription ID. The type assertion would panic on any successful subscribe; this has not been observed because the endpoint is not exercised in current deployments. Bundled into this PR at reviewer request (see PR omec-project#663 review discussion). Signed-off-by: Vinod Patmanathan <vinod.patmanathan@forsway.com>
added 2 commits
April 22, 2026 09:28
Adds nil-guards in three N1N2 message handlers so AMF doesn't panic when an AmfUe is reconstructed from MongoDB (EventChannel is tagged json:"-" and is only set by the NGAP dispatcher). When EventChannel is nil, bypass the event-channel dispatch and call the underlying procedure directly - the procedures already handle CM-IDLE/paging. Affected handlers in producer/n1n2message.go: - HandleN1N2MessageTransferRequest - HandleN1N2MessageTransferStatusRequest - HandleN1N2MessageSubscirbeRequest Signed-off-by: Vinod Patmanathan <vinod.patmanathan@forsway.com>
The event-channel path in HandleN1N2MessageSubscirbeRequest declared and type-asserted msg.RespData to *UeN1N2InfoSubscriptionCreateData (the request type) while N1N2MessageSubscribeProcedure actually returns *UeN1N2InfoSubscriptionCreatedData (the response type). Per TS 29.518, a successful subscribe returns UeN1N2InfoSubscriptionCreatedData with the allocated subscription ID. The type assertion would panic on any successful subscribe; this has not been observed because the endpoint is not exercised in current deployments. Bundled into this PR at reviewer request (see PR omec-project#663 review discussion). Signed-off-by: Vinod Patmanathan <vinod.patmanathan@forsway.com>
donivtech
force-pushed
the
fix/n1n2-nil-eventchannel-cm-idle
branch
from
April 22, 2026 07:28
f447e44 to
f9dace1
Compare
gab-arrobo
approved these changes
Apr 22, 2026
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.
Issue
AMF panics on nil-pointer dereference when the SMF sends an
N1N2MessageTransferrequest for a UE whose context was restored from MongoDB. Reachable from any deployment where the receiving AMF is not the same process that served the UE's initial NAS attach (HA, multi-replica, pod restart, crash recovery).Panic site:
producer/n1n2message.go:71Downstream consequence: the SMF gets HTTP 500, the buffered downlink packet that triggered the paging is dropped, and paging never happens for that UE.
RCA
AmfUe.EventChannelis the per-UE goroutine dispatch mechanism used by the three N1N2 HTTP handlers. It is created on demand by the NGAP dispatcher when a live NGAP message arrives (SetEventChannel).Two factors combine to produce the bug:
json:"-"— excluded from MongoDB serialisation. When anAmfUeis restored from DB, the field is zero-valued (nil).When an
AmfUeis restored from MongoDB and anN1N2MessageTransferarrives before any NGAP activity on that context,EventChannelis nil → panic.The paging logic inside
N1N2MessageTransferProcedureitself is correct — it handles CM-IDLE viaCmConnect()check +BuildPaging/SendPaging. The bug is purely in the HTTP wrapper that panics before the procedure can run.Why this is rarely seen in single-pod lab setups
On a single long-running AMF pod, the
EventChannelstays alive in memory even after the UE goes CM-IDLE (it is only torn down viaue.Remove()). So the bug is invisible until the AMF is recreated — which is exactly when any real deployment (k8s, HA) is exposed.Fix
Add a nil-guard at the top of each N1N2 handler. When
EventChannelis nil, bypass the event-channel dispatch and call the underlying procedure directly. The procedures are already written to handle CM-IDLE, so no new paging logic is introduced. Each fallback logs aWARNfor operator visibility.Three handlers patched in
producer/n1n2message.go:HandleN1N2MessageTransferRequestN1N2MessageTransferProcedureHandleN1N2MessageTransferStatusRequestN1N2MessageTransferStatusProcedureHandleN1N2MessageSubscirbeRequestN1N2MessageSubscribeProcedure48 lines added, 0 removed. Happy path (EventChannel non-nil) is unchanged.
Scope / risk
WARNlog lines when the fallback fires. Expected after any AMF restart with persisted UE contexts; not a new problem indicator.EventChannel. A deeper refactor to reconstruct it on deserialisation, or to remove the channel from the HTTP critical path, would be a separate PR.