java-topology/defects/nomad/patch/nomad-0004-checkstore-difference.md

31 lines
724 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# UNDF: UNDF-2026-000000479
# nomad-0004: checkstore.shim.Difference — O(current × ids)
## CWE
CWE-407: Inefficient Algorithmic Complexity
## Severity
MEDIUM
## Location
`client/serviceregistration/checks/checkstore/shim.go:152-155`
## Description
`Difference` iterates over all stored check IDs for an allocation and for
each calls `slices.Contains(ids, id)` — a linear scan over the input slice.
```go
for id := range s.current[allocID] {
if !slices.Contains(ids, id) { // O(|ids|)
remove = append(remove, id)
}
}
```
With C stored checks and I input IDs: O(C × I).
## Fix
Build a `map[structs.CheckID]struct{}` from `ids` before the loop.
## Speedup
~Ix speedup where I = len(ids).