mirror of
https://github.com/lukaszraczylo/traefikoidc.git
synced 2026-10-18 04:47:28 +00:00
review fixes apr 2026 (#130)
* Multiple fixes - refresh coordinator dedup + memory pressure wire - middleware sse consolidation + timer leak + claim cache - universal cache sync backfill + isDebug gate - lazy background task race - memory monitor stw cached + refresh() api * fix(auth): suppress OIDC redirects on non-navigation requests - [x] Add isNonNavigationRequest using Sec-Fetch-Mode and Accept headers - [x] Add comprehensive TestIsNonNavigationRequest - [x] Update ServeHTTP to 401 non-navigation and AJAX requests Fixes #129 * feat(config): add custom CA and insecure skip verify for OIDC TLS - [x] Add CACertPath, CACertPEM, InsecureSkipVerify to Config - [x] Implement loadCACertPool for CA bundle loading - [x] Update HTTPClientConfig with RootCAs and InsecureSkipVerify - [x] Apply CA pool and skip verify to pooled HTTP clients - [x] Enhance configKey to distinguish TLS configs - [x] Add comprehensive ca_cert_test.go Fixes #125 * feat(oidc): add custom CA certificate support for private OIDC providers - [x] Add caCertPath, caCertPEM, insecureSkipVerify config options - [x] Update traefik.yml with new OIDC client config fields - [x] Add configuration schema descriptions for new options - [x] Update README table and add Custom CA Certificates section * Fix the documentation. * test(redis): add oversized argument rejection test - [x] Add TestRedisConn_RejectOversizedArgumentBytes - [x] Import strings package * Dependencies cleanup
This commit is contained in:
+24
-15
@@ -9,13 +9,18 @@ import (
|
||||
// LazyBackgroundTask wraps BackgroundTask to provide delayed initialization.
|
||||
// This prevents memory leaks from unnecessary background tasks by starting
|
||||
// them only when actually needed, reducing resource usage in idle scenarios.
|
||||
//
|
||||
// Lifecycle is one-shot: once Stop has been called the task cannot be
|
||||
// restarted. The underlying BackgroundTask uses sync.Once for Start and
|
||||
// refuses to re-run after Stop, so restart is not supported by design.
|
||||
type LazyBackgroundTask struct {
|
||||
// BackgroundTask is the underlying task implementation
|
||||
*BackgroundTask
|
||||
// started tracks whether the task has been activated
|
||||
// mu guards the started flag against concurrent StartIfNeeded / Stop calls.
|
||||
mu sync.Mutex
|
||||
// started tracks whether the task has been activated.
|
||||
// Only mutated while holding mu.
|
||||
started bool
|
||||
// startOnce ensures single initialization
|
||||
startOnce sync.Once
|
||||
}
|
||||
|
||||
// NewLazyBackgroundTask creates a background task that doesn't start immediately.
|
||||
@@ -29,24 +34,28 @@ func NewLazyBackgroundTask(name string, interval time.Duration, taskFunc func(),
|
||||
}
|
||||
|
||||
// StartIfNeeded starts the background task only if it hasn't been started yet.
|
||||
// Uses sync.Once to ensure thread-safe single initialization.
|
||||
// Safe to call concurrently. After Stop has been called this is a no-op;
|
||||
// the task is not restartable.
|
||||
func (lt *LazyBackgroundTask) StartIfNeeded() {
|
||||
lt.startOnce.Do(func() {
|
||||
if !lt.started {
|
||||
lt.BackgroundTask.Start()
|
||||
lt.started = true
|
||||
}
|
||||
})
|
||||
lt.mu.Lock()
|
||||
defer lt.mu.Unlock()
|
||||
if lt.started {
|
||||
return
|
||||
}
|
||||
lt.BackgroundTask.Start()
|
||||
lt.started = true
|
||||
}
|
||||
|
||||
// Stop stops the background task if it was started.
|
||||
// Resets the start state to allow potential future re-initialization.
|
||||
// Once stopped, the task cannot be restarted (see type doc).
|
||||
func (lt *LazyBackgroundTask) Stop() {
|
||||
if lt.started {
|
||||
lt.BackgroundTask.Stop()
|
||||
lt.started = false
|
||||
lt.startOnce = sync.Once{}
|
||||
lt.mu.Lock()
|
||||
defer lt.mu.Unlock()
|
||||
if !lt.started {
|
||||
return
|
||||
}
|
||||
lt.BackgroundTask.Stop()
|
||||
lt.started = false
|
||||
}
|
||||
|
||||
// NewLazyCacheWithLogger creates a cache that doesn't start cleanup until first use.
|
||||
|
||||
Reference in New Issue
Block a user