Skip to content

SuggestionStore atomic save can leak .tmp file on Move failure #1574

Description

@Widthdom

Summary

SuggestionStore.SaveUnlocked writes to <file>.tmp then File.Move to the final path. There is no try/finally cleanup — if File.Move throws (e.g. file system error, anti-virus interference), the .tmp file is orphaned. Repeated failures accumulate orphan .tmp files in the .cdidx/ directory.

Evidence

  • src/CodeIndex/Cli/SuggestionStore.cs:236-246 — temp write + Move sequence with no cleanup on exception.

Impact

  • Slow disk leak in .cdidx/ on systems with intermittent FS issues.
  • Confusing .tmp files that look like in-progress writes long after the failure.

Proposed direction

  • Wrap the temp write/move in try { write; move } catch { try { File.Delete(tmpPath); } catch { } throw; } (or equivalent finally with existence check).
  • Optional: at startup, sweep <.cdidx>/*.tmp files older than N seconds.

Repro env

  • Branch: main @ 2ee912d (release v1.21.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions