Skip to content

fix(cache): validate TTL bounds to prevent immediate or infinite expiration (#445)#463

Open
Shubham-Gotawade wants to merge 1 commit into
agnivo988:mainfrom
Shubham-Gotawade:bugfix/cache-ttl-validation-445
Open

fix(cache): validate TTL bounds to prevent immediate or infinite expiration (#445)#463
Shubham-Gotawade wants to merge 1 commit into
agnivo988:mainfrom
Shubham-Gotawade:bugfix/cache-ttl-validation-445

Conversation

@Shubham-Gotawade

Copy link
Copy Markdown

Contributed as part of GSSoC '26. Implemented strict input validation boundaries on cache lifetime configurations to eradicate resource leaks and unstable cache states.

Problem Description

Within internal/cache/cache.go, the CacheConfig struct accepted raw time.Duration values for its TTL field without evaluating sanity bounds. Consequently, users or configuration Parsers could supply negative durations, zero durations, or abnormally large parameters.

When zero or negative fields are used, items expire instantly, completely defeating the purpose of the layer and triggering high computational overhead. Conversely, overly massive parameters prevent stale entries from being collected, leaking memory resources indefinitely. Fixes #445.

Solution Implemented

  1. Defensive Validation Interceptors: Established architectural bounds for allowable cache lifespans, constraining acceptable parameters between a baseline minimum of 1 minute (1 * time.Minute) and an upper ceiling of 7 days (7 * 24 * time.Hour).
  2. Structural Integrity Rules: Integrated validation rules to audit CacheConfig definitions prior to engine initialization. Invalid lifetimes now trigger explicit errors rather than poisoning runtime states.
  3. Table-Driven Regression Testing: Introduced complete test matrices inside internal/cache/cache_test.go. The test suite profiles edge cases including negative values (-5m), zero durations (0s), micro-values (10s), standard durations (2h), and out-of-bound configurations (10d) to ensure robust safety guarantees.

Verification & Test Logs

  • Local package verification via go test -v ./internal/cache/...: PASSED
  • Full workspace baseline compilation via go build ./...: PASSED

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@Shubham-Gotawade, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 35 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 54a942d1-e0eb-414c-b612-0122d7fe712e

📥 Commits

Reviewing files that changed from the base of the PR and between 6d6fa89 and 8f33983.

📒 Files selected for processing (2)
  • internal/cache/cache.go
  • internal/cache/cache_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache configuration TTL accepts zero or negative values, causing immediate expiration or infinite validity

1 participant