Skip to content

Feature: remove-unnecessary-interlocked-increment-in-fileio2 #709

Description

@drmoisan
  • Work Mode: minor-audit

Problem / Why

The retry loop in UtilitiesCS/To Depricate/FileIO2.cs increments its attempt counter with Interlocked.Increment(ref attempts). The counter is a method-local captured by the async state machine and is never touched by more than one logical thread, so the interlocked operation guards against contention that cannot occur. It reads as evidence of a concurrency concern that is not present, which is misleading to a later reader.

Implementation Intent

Replace Interlocked.Increment(ref attempts) with a plain increment, leaving the loop's control flow, the 100-attempt budget, and the 100-millisecond interval unchanged.

Acceptance Criteria

  • UtilitiesCS/To Depricate/FileIO2.cs contains zero occurrences of Interlocked.Increment.
  • The existing seam-driven tests in UtilitiesCS.Test/HelperClasses/FileIO2_Tests.cs still assert a writer-factory invocation count of 100 and a delay-delegate invocation count of 99 on the exhaustion path, and still pass.
  • No other behavior of WriteTextFileAsync changes.

Dependencies / Risks

  • The change is cosmetic. The existing call is unnecessary but harmless, so the value is readability rather than correctness, and the item should not be prioritized above defect work.
  • Issue Bug: fileio2-write-retry-reports-success-on-final-failure #647 listed replacing this call as an explicit non-goal and deliberately retained it, so the change must not be folded into any in-flight work on that file.
  • If WriteTextFileAsync is later deleted by the To Depricate migration item, this item becomes moot and should be closed rather than executed.

Verification Steps

  • Unit coverage areas: the two existing exhaustion-path assertions are sufficient; no new test is required.
  • Integration scenarios: none; the change is local to one method.
  • CLI/API examples: not applicable.

Evidence Checklist

  • Baseline
  • End-state
  • Targeted verification

Source

From: docs/features/potential/2026-08-31-remove-unnecessary-interlocked-increment-in-fileio2.md

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureFeature request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions