mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-16 05:37:28 +00:00
fix(registry): defer context cancels on the refresh panic path
A panic in listModels skipped the inline cancel, holding the timeout timer until it fired. Review follow-up from the v0.2.3 final verdict.
This commit is contained in:
+7
-2
@@ -547,17 +547,22 @@ func (m *modelRegistry) refreshProvider(name string, st *providerState, adapter
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// Both cancels are deferred: this function has a recover above, so a
|
||||||
|
// panicking listModels would skip an inline cancel() and hold the
|
||||||
|
// timer until backgroundRefreshTimeout fires. Deferring costs nothing
|
||||||
|
// (the function ends right after the capture) and survives the panic
|
||||||
|
// path.
|
||||||
fctx, cancel := context.WithTimeout(context.Background(), backgroundRefreshTimeout)
|
fctx, cancel := context.WithTimeout(context.Background(), backgroundRefreshTimeout)
|
||||||
|
defer cancel()
|
||||||
ids, err = adapter.listModels(fctx)
|
ids, err = adapter.listModels(fctx)
|
||||||
cancel()
|
|
||||||
|
|
||||||
// Own timeout budget, review fix (SHOULD-4) — see warmFill's
|
// Own timeout budget, review fix (SHOULD-4) — see warmFill's
|
||||||
// identical comment: reusing fctx here would hand the metadata fetch
|
// identical comment: reusing fctx here would hand the metadata fetch
|
||||||
// an already-spent context on every refresh whose listModels call
|
// an already-spent context on every refresh whose listModels call
|
||||||
// ran long, not just a slow or timed-out one.
|
// ran long, not just a slow or timed-out one.
|
||||||
mctx, mcancel := context.WithTimeout(context.Background(), backgroundRefreshTimeout)
|
mctx, mcancel := context.WithTimeout(context.Background(), backgroundRefreshTimeout)
|
||||||
|
defer mcancel()
|
||||||
m.captureModelMetadata(mctx, name, adapter, st)
|
m.captureModelMetadata(mctx, name, adapter, st)
|
||||||
mcancel()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// splitConfiguredProvider reports whether id has "prefix/rest" form where
|
// splitConfiguredProvider reports whether id has "prefix/rest" form where
|
||||||
|
|||||||
Reference in New Issue
Block a user