Skip to content

fix(client): avoid nil-cache panic in Client.RemoveData#708

Open
sozercan wants to merge 1 commit intomasterfrom
codex/fix-removedata-nil-cache-panic-issue
Open

fix(client): avoid nil-cache panic in Client.RemoveData#708
sozercan wants to merge 1 commit intomasterfrom
codex/fix-removedata-nil-cache-panic-issue

Conversation

@sozercan
Copy link
Copy Markdown
Member

@sozercan sozercan commented Apr 9, 2026

Motivation

  • handler.Cacher.GetCache() is permitted to return nil according to the interface contract, but Client.RemoveData previously dereferenced the returned cache unconditionally causing a nil-pointer panic when a handler returns nil and enabling an availability-impacting DoS during deletions.

Description

  • Add a nil guard before calling Remove on a target handler cache in constraint/pkg/client/client.go so RemoveData checks cache != nil before invoking cache.Remove(relPath).
  • Add a test helper nilCacheHandler that implements handler.Cacher and returns nil from GetCache() in constraint/pkg/client/client_test.go.
  • Add TestClient_RemoveData_NilCache in constraint/pkg/client/client_test.go to verify RemoveData does not panic or return an error when a handler returns a nil cache.

Testing

  • Ran go test ./pkg/client -run '^TestClient_RemoveData_NilCache$' -v inside the constraint/ module and the test passed.
  • Ran go test ./pkg/client -run '^TestClient_RemoveData_Cache$' -v inside the constraint/ module and the test passed.
  • Attempting go test ./constraint/pkg/client -run 'TestClient_RemoveData_(Cache|NilCache)$' from the repository root failed due to module layout (module is under constraint/), not due to the code change.

Codex Task

Copilot AI review requested due to automatic review settings April 9, 2026 19:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) in Client.RemoveData.
  • Add a test-only nilCacheHandler that returns a nil cache.
  • Add TestClient_RemoveData_NilCache to ensure RemoveData doesn’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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants