From 701936d18030445b5a82c4e346cd5fd83aa914ab Mon Sep 17 00:00:00 2001 From: DBGR18 Date: Tue, 30 Jun 2026 12:01:59 +0800 Subject: [PATCH 1/2] fix: cache AccessToken client by nrfUri to stop unbounded clientMap growth Co-Authored-By: Claude Opus 4.8 --- oauth/get_token_context.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/oauth/get_token_context.go b/oauth/get_token_context.go index eeea46ef..b0faf641 100644 --- a/oauth/get_token_context.go +++ b/oauth/get_token_context.go @@ -33,14 +33,18 @@ func sendAccTokenReq( ) (oauth2.TokenSource, *models.ProblemDetails, error) { var client *AccessToken.APIClient - configuration := AccessToken.NewConfiguration() - configuration.SetBasePath(nrfUri) - - if val, ok := clientMap.Load(configuration); ok { + // Cache the API client by the stable nrfUri. Previously the cache was keyed + // by the freshly-allocated *Configuration returned by NewConfiguration(), + // whose pointer differs on every call, so the lookup never hit and a new + // entry (each holding an *APIClient with its own http.Client) was stored on + // every token request, leaking unboundedly under SBI load. + if val, ok := clientMap.Load(nrfUri); ok { client = val.(*AccessToken.APIClient) } else { + configuration := AccessToken.NewConfiguration() + configuration.SetBasePath(nrfUri) client = AccessToken.NewAPIClient(configuration) - clientMap.Store(configuration, client) + clientMap.Store(nrfUri, client) } var tok models.NrfAccessTokenAccessTokenRsp From c38a2e1f0cd0c15729dba16a3a3ee40fea084828 Mon Sep 17 00:00:00 2001 From: DBGR18 Date: Mon, 6 Jul 2026 16:33:03 +0800 Subject: [PATCH 2/2] fix: remove redundant comments --- oauth/get_token_context.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/oauth/get_token_context.go b/oauth/get_token_context.go index b0faf641..8b452ead 100644 --- a/oauth/get_token_context.go +++ b/oauth/get_token_context.go @@ -33,11 +33,6 @@ func sendAccTokenReq( ) (oauth2.TokenSource, *models.ProblemDetails, error) { var client *AccessToken.APIClient - // Cache the API client by the stable nrfUri. Previously the cache was keyed - // by the freshly-allocated *Configuration returned by NewConfiguration(), - // whose pointer differs on every call, so the lookup never hit and a new - // entry (each holding an *APIClient with its own http.Client) was stored on - // every token request, leaking unboundedly under SBI load. if val, ok := clientMap.Load(nrfUri); ok { client = val.(*AccessToken.APIClient) } else {