Skip to content

Fix retention sweep after backward clock adjustments - #235

Merged
enteriaza merged 1 commit into
masterfrom
189-bug-retention-sweep-backward-clock
Oct 21, 2026
Merged

enteriaza merged 1 commit into
masterfrom
189-bug-retention-sweep-backward-clock

Conversation

@enteriaza

Copy link
Copy Markdown
Collaborator

Summary

Fixes #189.

Ensure the retention sweep removes all expired articles even when the system wall clock moves backward and expiry timestamps no longer follow insertion order.

Root cause

ExpireEligibleLocked walked the insertion-order linked list and stopped at the first entry whose ExpiresUtc was later than the current time. This assumed expiration order matched insertion order.

After a backward clock adjustment, a later-admitted article can have an earlier expiration timestamp than an older entry. The sweep would stop at the older, unexpired entry and leave subsequent expired articles resident, consuming retained-payload capacity unnecessarily.

Changes

  • Scan the full retention list: Continue past unexpired entries and remove every entry whose ExpiresUtc <= now.
  • Preserve safe iteration: Capture the next linked-list node before removing the current entry.
  • Preserve FIFO reclamation: Capacity-based reclamation continues to use insertion order; the expiry fix does not change that policy.
  • Improve deterministic clock testing: Add SetUtcNow to ManualTimeProvider to simulate backward clock adjustments without relying on real-time delays.
  • Add regression coverage: Introduce ArticleRetentionSweepClockTests for backward-clock expiry, multiple expired entries separated by unexpired entries, exact expiry boundaries, and FIFO behaviour.

Validation

  • Retention-filtered tests: 55 passed
  • VectorNNTPD.BackFillerService.Tests: 1,328 passed
  • Release x64 solution build: succeeded, 0 warnings
  • dotnet format VectorNNTP.slnx --verify-no-changes: passed
  • tools/Invoke-CodeQlAnalysis.ps1: completed successfully; six pre-existing NntpSessionPool findings remain.

Correctness guarantees

  • Every entry with ExpiresUtc <= now is eligible for removal during the sweep, regardless of insertion position.
  • Unexpired entries remain retained.
  • Retained-payload byte accounting is updated as entries are removed.
  • FIFO capacity-reclamation behaviour remains unchanged.
  • The sweep no longer relies on wall-clock time progressing monotonically.

@enteriaza enteriaza self-assigned this Oct 21, 2026
@enteriaza enteriaza added the bug Something isn't working label Oct 21, 2026
@enteriaza
enteriaza merged commit b5f7ad6 into master Oct 21, 2026
7 checks passed
@enteriaza
enteriaza deleted the 189-bug-retention-sweep-backward-clock branch October 21, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Retention sweep leaves later expired articles resident after a backward clock step

1 participant