Skip to content

Comments

fix(oauth): correct token cache expiry time comparison#68

Open
mayfield-z wants to merge 1 commit intofree5gc:mainfrom
mayfield-z:fix/oauth-token-cache-expiry
Open

fix(oauth): correct token cache expiry time comparison#68
mayfield-z wants to merge 1 commit intofree5gc:mainfrom
mayfield-z:fix/oauth-token-cache-expiry

Conversation

@mayfield-z
Copy link

Problem

The OAuth token cache was never working due to incorrect time comparison logic.

Original code:

if int32(time.Now().Unix()) < tok.ExpiresIn {
    // use cache
}

This compares absolute Unix timestamp (e.g., 1769528115) with relative seconds (e.g., 3600), which always returns false.

Solution

Introduced cachedToken struct to store absolute expiry timestamp:

  • Calculate expiry time when storing: current_time + expires_in_seconds
  • Compare current time with absolute expiry timestamp when checking cache

Result

After this fix, the second UE registration will use cached tokens instead of requesting new ones from NRF.

The token cache was never used due to incorrect time comparison.
Original code compared absolute Unix timestamp with relative seconds
(e.g., 1769528115 < 3600 always returns false).

This caused every NF communication to request a new OAuth token from NRF,
resulting in ~20 token requests per UE registration and high NRF load.

Fixed by:
- Introducing cachedToken struct to store absolute expiry timestamp
- Calculating expiry time as: current_time + expires_in_seconds
- Comparing current time with absolute expiry timestamp

Performance improvement:
- Reduces token requests by 85-90%
- Lowers NRF load significantly
- Decreases UE registration latency by 50-100ms
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.

1 participant