Memleak fixes.

This commit is contained in:
2025-05-09 19:05:24 +01:00
parent 81000a824d
commit da70e69ad1
4 changed files with 120 additions and 30 deletions
+10
View File
@@ -38,11 +38,13 @@ type JWKCache struct {
mutex sync.RWMutex
// CacheLifetime is configurable to determine how long the JWKS is cached.
CacheLifetime time.Duration
internalCache *Cache // To hold the closable Cache instance from cache.go
}
type JWKCacheInterface interface {
GetJWKS(ctx context.Context, jwksURL string, httpClient *http.Client) (*JWKSet, error)
Cleanup()
Close()
}
// GetJWKS retrieves the JSON Web Key Set (JWKS) from the cache or fetches it from the provider.
@@ -101,6 +103,14 @@ func (c *JWKCache) Cleanup() {
}
}
// Close shuts down the cache's auto-cleanup routine.
func (c *JWKCache) Close() {
// Close shuts down the internal cache's auto-cleanup routine, if the cache exists.
if c.internalCache != nil {
c.internalCache.Close()
}
}
// fetchJWKS retrieves the JSON Web Key Set (JWKS) from the specified URL.
// It uses the provided context and HTTP client to make the request.
//