mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-10-14 05:18:54 +00:00
fix(registry): recover refresh goroutine, per-provider warm-fill budget, exact-glob model authorization
1. refreshProvider (the plugin's only background goroutine) had no recover(): a panicking adapter's listModels would crash the whole Traefik process. Restructured around deferred recover + finishRefresh, so a panic is turned into a logged error, inFlight always releases, and the next interval retries. Documented as a scoped exception to limits.go's no-background-goroutine rule. 2. newGateway wrapped ctx in an outer 5s WithTimeout before warmFill, but warmFill already derives a fresh 5s budget per provider from whatever ctx it receives. The outer wrap made that a single budget shared across every discovery-enabled provider instead of a per-provider one - providers after the first could get a near-expired context and fail instantly. Dropped the outer wrapper; construction's worst case is now N * 5s, accepted. 3. group.allowsModel stripped at any first slash, so a glob like 'deepseek-*' could spuriously match a bare model id that merely contains a slash (e.g. an upstream's own 'uni/deepseek-v4-flash-0731' naming) even though the leading segment names no configured provider. allowsModel is now an exact glob with no internal splitting; resolveAgainst and listFor generate the provider-prefixed and bare-suffix candidates themselves, only when a prefix legitimately names a configured provider. Updated the Task-3 TestIdentify assertion to match. 4. Annotated the discarded json.Encode error in handleModels. Gate: go test ./... -count=1, -race, gofmt, vet, fieldalignment, golangci-lint (incl gosec) all clean.
This commit is contained in:
@@ -32,18 +32,19 @@ func (grp *group) allowsProvider(name string) bool {
|
||||
}
|
||||
|
||||
// allowsModel reports whether id matches one of the group's model glob
|
||||
// patterns. An empty pattern list allows every model. A pattern is checked
|
||||
// against id as given and, when id has a "provider/model" form, against the
|
||||
// part after the "/" — so a pattern like "gpt-5*" matches both "gpt-5-mini"
|
||||
// and "openai/gpt-5-mini".
|
||||
// patterns, exactly as given. An empty pattern list allows every model.
|
||||
//
|
||||
// allowsModel does no "provider/model" prefix-splitting of its own — a
|
||||
// pattern like "deepseek-*" must not spuriously match a bare model id that
|
||||
// merely happens to contain a slash (e.g. an upstream's own
|
||||
// "uni/deepseek-v4-flash-0731" naming, where "uni" is not a configured
|
||||
// provider: there is no legitimate prefix to strip there at all). A caller
|
||||
// that genuinely knows an id's leading segment names a configured provider
|
||||
// (modelRegistry.resolveAgainst, modelRegistry.listFor) generates both the
|
||||
// full and bare-suffix candidate strings itself and calls allowsModel once
|
||||
// per candidate.
|
||||
func (grp *group) allowsModel(id string) bool {
|
||||
if matchesGlob(grp.models, id) {
|
||||
return true
|
||||
}
|
||||
if _, bare, found := strings.Cut(id, "/"); found {
|
||||
return matchesGlob(grp.models, bare)
|
||||
}
|
||||
return false
|
||||
return matchesGlob(grp.models, id)
|
||||
}
|
||||
|
||||
// allowsMCP reports whether name matches one of the group's MCP-server glob
|
||||
|
||||
Reference in New Issue
Block a user