fix(client): avoid nil-cache panic in Client.RemoveData#708
Open
fix(client): avoid nil-cache panic in Client.RemoveData#708
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens Client.RemoveData against nil-cache implementations of handler.Cacher, preventing a nil-pointer panic during deletions when a handler returns nil from GetCache() as permitted by the interface contract.
Changes:
- Add a nil guard around
cache.Remove(relPath)inClient.RemoveData. - Add a test-only
nilCacheHandlerthat returns anilcache. - Add
TestClient_RemoveData_NilCacheto ensureRemoveDatadoesn’t panic and returns no error when a handler exposes a nil cache.
Show a summary per file
| File | Description |
|---|---|
| constraint/pkg/client/client.go | Adds cache != nil guard before calling Remove in RemoveData to prevent nil dereference. |
| constraint/pkg/client/client_test.go | Introduces a nil-cache handler and a regression test validating RemoveData behavior with nil caches. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
JaydipGabani
approved these changes
Apr 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
handler.Cacher.GetCache()is permitted to returnnilaccording to the interface contract, butClient.RemoveDatapreviously dereferenced the returned cache unconditionally causing a nil-pointer panic when a handler returnsniland enabling an availability-impacting DoS during deletions.Description
Removeon a target handler cache inconstraint/pkg/client/client.gosoRemoveDatacheckscache != nilbefore invokingcache.Remove(relPath).nilCacheHandlerthat implementshandler.Cacherand returnsnilfromGetCache()inconstraint/pkg/client/client_test.go.TestClient_RemoveData_NilCacheinconstraint/pkg/client/client_test.goto verifyRemoveDatadoes not panic or return an error when a handler returns a nil cache.Testing
go test ./pkg/client -run '^TestClient_RemoveData_NilCache$' -vinside theconstraint/module and the test passed.go test ./pkg/client -run '^TestClient_RemoveData_Cache$' -vinside theconstraint/module and the test passed.go test ./constraint/pkg/client -run 'TestClient_RemoveData_(Cache|NilCache)$'from the repository root failed due to module layout (module is underconstraint/), not due to the code change.Codex Task