Skip to content

Commit 2a556a9

Browse files
fix: improve deadline detection and fix misleading comment in discovery
Use errors.Is for wrapped context.DeadlineExceeded detection in both retry and HTTP request paths. Remove incorrect CheckedAt reference from FilterModelsByAccess doc comment. Signed-off-by: Wen Liang <liangwen12year@gmail.com>
1 parent adcb9a4 commit 2a556a9

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

maas-api/internal/models/discovery.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ func NewManager(log *logger.Logger) (*Manager, error) {
7575
// 2xx or 405 → include, 401/403/404 → exclude.
7676
// Models with nil URL are skipped. Concurrency is limited by maxDiscoveryConcurrency.
7777
//
78-
// The result includes a CheckedAt timestamp indicating when the access probes completed.
7978
// Because authorization policies propagate asynchronously through the gateway, there is an
8079
// inherent eventual-consistency window: a model listed here may become inaccessible (or vice versa)
8180
// by the time the client acts on the response. Actual enforcement always happens at the gateway
@@ -228,7 +227,7 @@ func (m *Manager) fetchModelsWithRetry(ctx context.Context, authHeader string, s
228227
lastResult = authRes
229228
return lastResult != authRetry, nil
230229
}); err != nil {
231-
if ctx.Err() == context.DeadlineExceeded {
230+
if errors.Is(err, context.DeadlineExceeded) || ctx.Err() == context.DeadlineExceeded {
232231
m.logger.Debug("Access validation failed: context deadline exceeded", "service", meta.ServiceName, "endpoint", meta.Endpoint, "timeout", accessCheckTimeout)
233232
} else {
234233
m.logger.Debug("Access validation failed: model fetch backoff exhausted", "service", meta.ServiceName, "endpoint", meta.Endpoint, "error", err)
@@ -259,7 +258,7 @@ func (m *Manager) fetchModels(ctx context.Context, authHeader string, subscripti
259258
// #nosec G704 -- Intentional HTTP request to probe model endpoint for authorization check
260259
resp, err := m.httpClient.Do(req)
261260
if err != nil {
262-
if ctx.Err() == context.DeadlineExceeded {
261+
if errors.Is(err, context.DeadlineExceeded) || ctx.Err() == context.DeadlineExceeded {
263262
m.logger.Debug("Access validation: request timed out (context deadline exceeded)", "service", meta.ServiceName, "endpoint", meta.Endpoint)
264263
return nil, authDenied // fail-closed, no point retrying a deadline
265264
}

0 commit comments

Comments
 (0)