feat(nfheartbeat): add NF heartbeat runner - #48
Open
Niahh wants to merge 1 commit into
Open
Conversation
Drive the periodic NF heartbeat toward the NRF from a shared package, per 3GPP TS 29.510 clause 5.2.2.3.2: adopt the interval carried by NRF answers, re-register on 404 or after consecutive failures, and wait for the loop at shutdown so no heartbeat lands after the deregistration. Each NF supplies only its transport through the Registrar interface.
This was referenced Aug 7, 2026
Contributor
Author
|
Hey team, any thoughts on this new feature ? |
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 NRF, the other SBI NFs and the configuration files.
free5gc/ausf#67
free5gc/nrf#95
I will create PR for the other NFs after these design is accepted.
This PR addresses the following:
Presentation of the changes
New nfheartbeat package
A single
Runnerdrives the NF heart-beat toward the NRF. Each NF supplies only its transport, through theRegistrarinterface:The Runner decides when to heart-beat or re-register, the Registrar carries it out, so the SBI clients, the OAuth2 token handling and the NF profile stay on the NF side.
PatchItems()returns the body from clause 5.2.2.3.2 (replace/nfStatusREGISTERED) so no NF has to spell it out.Startlaunches the loop after a successful registration and takes the heartBeatTimer the NRF assigned there.Waitblocks until the goroutine has exited, which is the guarantee the deregistration relies on: no heart-beat PATCH and no re-registration PUT can reach the NRF afterwards.Interval ownership
The NRF owns the interval. The value from the registration response is adopted, and every 200 heart-beat answer carrying a new one re-arms the ticker. A 204 carries nothing and the current interval stands, and so does a 200 whose heartBeatTimer is 0: the int32 model cannot tell an explicit 0 from an absent field, so 0 must not read as "disable" the way the legacy
openapinrf/service.go helper reads it.While the NRF has assigned nothing, the interval comes from the
fallbackTimercallback each NF passes, typically its config getter, and then fromDefaultTimer. An NRF-assigned value aboveMaxTimeris capped, so a misbehaving NRF cannot park the heart-beat for hours.DefaultTimer(10),MinTimer(1) andMaxTimer(3600) are exported: they match the NRF defaults and the heartBeatTimer bounds of the NRF profile validation, and NF config validators are expected to stay within them. A fallback longer than the NRF default would cross the deadline past which the NRF suspends a silent instance.Recovery
The loop recovers from NRF-side profile loss, which the NRF PR can now cause on purpose (dropDelay):
openapi.GenericOpenAPIErrorby value or by pointer.Shutdown wins over recovery: a tick that fires while the context is already cancelled is skipped, a re-registration is skipped for the same reason, and a
Startthat raced the shutdown does nothing.New dependency
github.com/free5gc/openapibecomes a direct dependency of util. The package needsmodelsfor the PatchItem body and the NF profile, andopenapi.GenericOpenAPIErrorto classify the 404. openapi does not depend on util, so there is no cycle.Testing
Startignored,Starton a cancelled context, tick and re-registration skipped on shutdown,Waitreturning when the heart-beat never started.TestWaitCoversInFlightTickpins the guarantee deregistration relies on:Waitdoes not return while a PATCH is still in flight, even after the shutdown was signalled.testing/synctestfake clock rather than real sleeps.This work is sponsored by Free Mobile!