Skip to content

refactor(ttlcleaner): align pkg/common/ttlcleaner with KHI coding rules - #1319

Open
kyasbal wants to merge 1 commit into
mainfrom
push-sqlqnusyqvnn
Open

kyasbal wants to merge 1 commit into
mainfrom
push-sqlqnusyqvnn

Conversation

@kyasbal

@kyasbal kyasbal commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Aligns pkg/common/ttlcleaner with KHI Go coding and testing conventions without modifying exported APIs, while fixing five concurrency and lifecycle bugs:

  • Replaces the unsynchronized sync.WaitGroup + running + shared stopChan lifecycle with mutex-guarded per-run stopChan and doneChan channels (tryStart / run), eliminating Start/Stop races and WaitGroup reuse panics.
  • Makes Start -> Stop -> Start restarts safe and single-flight (Start waits for any stopping run goroutine to finish before spawning a new one).
  • Ensures all concurrent Stop() callers wait until any in-flight Sweep() and ticker teardown complete.
  • Moves time.NewTicker(c.interval) into tryStart() before mutating state so a non-positive interval panics synchronously without leaving corrupted state or crashing an unrecoverable background goroutine.
  • Prioritizes <-stopChan over buffered <-ticker.C ticks during shutdown and registers LIFO defers so ticker.Stop() completes before doneChan closes.
  • Migrates timing-dependent tests from time.Sleep to testing/synctest and adds boundary, partial-eviction error isolation, restart, concurrent Stop/Start barrier, non-positive interval panic, and -race stress tests (100.0% statement coverage).

Verification

  • make pre-push — PASS (0 mustfix, 0 advisory, 0 skipped)
  • make qa-all-advisory CODEQUALITY_SIMILARITY=true — PASS (0 mustfix, 0 advisory, 0 skipped; 8/8 mutants killed, 0 similarity advisories)
  • go test -race -count=1 -cover ./pkg/common/ttlcleaner/... ./pkg/server/chunkedupload/... ./pkg/server/streamingutil/... — PASS (pkg/common/ttlcleaner: 100.0% statement coverage)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the TTLCleaner implementation to improve concurrency safety, idempotency, and support restarting. The internal synchronization mechanism was updated to replace sync.WaitGroup and a boolean running flag with coordinated stopChan and doneChan channels, ensuring that Stop() waits for any in-flight sweep to complete. Additionally, the test suite was significantly expanded using testing/synctest to cover edge cases such as stopping before starting, restarting, concurrent races, and synchronous panics on non-positive intervals. There are no review comments, and I have no feedback to provide.

@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Go Quality Report (origin/main) — ✅ PASS

Metric Result
Changed Scope 1 prod file(s), 1 test file(s), 8 unit(s)
Patch Coverage 100.0% (35/35 lines)
Mutation Score 100.0% (8/8 killed, 0 survived)
Function Similarity OK (2 new unit(s), 0 matches across 3185 corpus units)

Commit: ddda61c7d36b · Cloud Build Logs

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

Labels

None yet

1 participant