feat(consumer): send periodic NF heartbeat to NRF - #67
Open
Niahh wants to merge 1 commit into
Open
Conversation
Niahh
force-pushed
the
feat/nrf-heartbeat
branch
from
August 6, 2026 16:18
dadda09 to
856cc7e
Compare
Send an NFUpdate PATCH with nfStatus REGISTERED at the interval the NRF returns, per 3GPP TS 29.510 clause 5.2.2.3.2. Re-adopt heartBeatTimer from every answer. Re-register on 404 or after three consecutive failures. The heartbeat loop lives in the util nfheartbeat package; the consumer only supplies the PATCH and re-registration transport. The nfHeartBeatTimer config option only sets the fallback interval. The NRF value always wins. Also drop the instance ID parsed from the register response Location. Guard the NRF client lookups against a nil client. Make the registration retry cancellable. Wait for the heartbeat goroutine before deregistering.
Niahh
force-pushed
the
feat/nrf-heartbeat
branch
from
August 7, 2026 13:45
856cc7e to
5d0a8d2
Compare
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.
Hello,
This PR is part of a series of PRs that will also modify the other SBI NFs and the configuration file. It depends on the util PR adding the shared
nfheartbeatpackage, and on the NRF PR enforcing the procedure on the other side.free5gc/util#48
free5gc/nrf#95
It addresses the following:
Presentation of the changes
Heart-beat feature
After a successful registration, the AUSF starts the heart-beat runner from
util/nfheartbeat, which sends the NFUpdate PATCH of clause 5.2.2.3.2 (replace/nfStatusREGISTERED) at the current interval. The loop, the interval ownership, the recovery and the panic containment live in the shared package; the AUSF supplies only the transport, through a smallnrfRegistraradapter overnnrfService:UpdateNFInstanceis the newSendUpdateNFInstance.RegisterNFInstanceis the existing registration, and returns the heartBeatTimer the NRF assigned.Behaviour that follows from the shared runner: the NRF owns the interval (adopted from the registration response, re-armed by every 200 answer carrying a new value, a 204 leaves it as is), a 404 on the heart-beat re-registers immediately, 3 consecutive failures of any kind do too, and a panic inside a tick costs one heart-beat instead of ending them all.
A new optional
nfHeartBeatTimerconfiguration IE serves as fallback while the NRF has not assigned an interval.On shutdown the ordering matters:
terminateProcedurewaits for the heart-beat goroutine to exit before sending the NFDeregister, so no heart-beat PATCH or re-registration PUT can resurrect the profile on the NRF afterwards.SendUpdateNFInstance
New consumer call for the NFUpdate PATCH. It returns the raw error alongside any ProblemDetails, so the runner can read the
GenericOpenAPIErrorstatus and classify a 404 even when the NRF answers without a problem body.It honours the caller's context.
GetTokenCtxtakes no parent, so the token request itself stays uncancellable; transplanting the token into the caller's context lets at least the PATCH observe a shutdown.Registration hardening
RegisterNFInstancenow runs on the application context instead ofcontext.Background(), and the 2s retry wait is interruptible, so a shutdown during an NRF outage returns immediately instead of sleeping through it.processRegisterResponseand now also covers the 200 (profile already known to the NRF), which previously fell through without adopting anything, heartBeatTimer included.applyOAuth2argument.OAuth2Requiredis read concurrently by the SBI handlers once the server runs, so a re-registration from the heart-beat goroutine may not write it: if the NRF flips the setting later, the AUSF logs a warning asking for a restart instead of racing the handlers.RegisterNFInstancereturns only an error now. It no longer parses the Location header: NFRegister is a PUT on the instance ID the AUSF chose (clause 6.1.3.2.2), so the NRF echoes that ID back and the parsing could only reproduce it or corrupt it. A Location ending in a slash yielded an empty ID, which was then written to the AUSF context.Other changes
These are pre-existing, but the heart-beat goroutine is what makes them reachable.
getNFManagementClientreturns nil when nrfUri is empty.RegisterNFInstance,SendUpdateNFInstanceandSendDeregisterNFInstanceall dereferenced it. They now report the error the waySendSearchNFInstancesalready did, so a misconfigured nrfUri is an error instead of a panic on every heart-beat tick.SendDeregisterNFInstancetook its token context from the globalausf_context.GetSelf()while taking its client from the injected context. Both resolve to the same pointer at runtime; it now uses the injected one consistently.New configuration IE:
The field is optional and defaults to
nfheartbeat.DefaultTimer, 10 seconds, which matches the NRF default interval. A longer fallback would reach past the deadline at which the NRF suspends a silent instance. The 1~3600 range mirrors the heartBeatTimer bounds of the NRF profile validation.Testing
SendUpdateNFInstanceis tested for the 200 with profile, the 204, the ProblemDetails extraction and the missing nrfUri;RegisterNFInstancefor the 201 and 200 handling, the retry until success, and the return on context cancellation.testing/synctestfake clock rather than real sleeps.This work is sponsored by Free Mobile!