Saving a runtime settings file on Windows works while another reader has it open #13

Closed
opened 2026-10-31 12:41:49 -04:00 by claude · 1 comment
Owner
  • Draft: REL-7
  • Priority: medium (may be a product defect: a settings write that fails on Windows)
  • Agent: coder
  • Depends on: none
  • Decisions: none

Why

WebhookDeliveryServiceHotReloadTests.AWriteThrough... fails on Windows with "Unable to remove
the file to be replaced" from StagedFile.Commit
(src/dotnet/src/Ninlil.Dns.Common/IO/StagedFile.cs:30-32). On Windows the commit uses
File.Replace, which fails when another handle on the target lacks delete sharing (for example
the configuration file reloader or the test reading it). If the product's own reader can hold the
file at that moment, a settings write from the API can fail on Windows.

What changes

  • Find which handle blocks the replace (test or product). If product: make the writers and
    readers of the runtime configuration file open it with FileShare.ReadWrite | FileShare.Delete,
    or retry the replace briefly on a sharing violation, keeping the ACL-preserving behaviour the
    comment at StagedFile.cs:31 describes. If test-only, fix the test.
  • Red-then-green on Windows (git bundle on Lofnheim); a guard test on Linux.

Acceptance

  • The test passes on Lofnheim natively; Ninlil.Dns.Common is shared, so the whole solution
    passes on Linux.
  • The issue states whether a live settings write on Windows could fail before the fix, with
    the evidence.

Source

RP-4 report finding 3 (WebhookDeliveryServiceHotReloadTests, StagedFile.cs:32).

- **Draft:** REL-7 - **Priority:** medium (may be a product defect: a settings write that fails on Windows) - **Agent:** coder - **Depends on:** none - **Decisions:** none ### Why `WebhookDeliveryServiceHotReloadTests.AWriteThrough...` fails on Windows with "Unable to remove the file to be replaced" from `StagedFile.Commit` (`src/dotnet/src/Ninlil.Dns.Common/IO/StagedFile.cs:30-32`). On Windows the commit uses `File.Replace`, which fails when another handle on the target lacks delete sharing (for example the configuration file reloader or the test reading it). If the product's own reader can hold the file at that moment, a settings write from the API can fail on Windows. ### What changes - Find which handle blocks the replace (test or product). If product: make the writers and readers of the runtime configuration file open it with `FileShare.ReadWrite | FileShare.Delete`, or retry the replace briefly on a sharing violation, keeping the ACL-preserving behaviour the comment at `StagedFile.cs:31` describes. If test-only, fix the test. - Red-then-green on Windows (git bundle on Lofnheim); a guard test on Linux. ### Acceptance - [ ] The test passes on Lofnheim natively; Ninlil.Dns.Common is shared, so the whole solution passes on Linux. - [ ] The issue states whether a live settings write on Windows could fail before the fix, with the evidence. ### Source RP-4 report finding 3 (`WebhookDeliveryServiceHotReloadTests`, `StagedFile.cs:32`).
Author
Owner

Done on feature/8-windows-test-suite (99f6d568).

Could a live settings write on Windows fail before the fix? Yes, briefly. A configuration provider with reloadOnChange re-reads the runtime file shortly after every write. While its read handle is open without delete sharing, File.Replace in StagedFile.Commit fails. So a settings write that lands during the previous write's reload, or during an operator's quick second write, could fail. Ninlil's own readers use File.ReadAllText and close at once, and writers are serialised by AtomicFile.GetPathLock.

Evidence on Lofnheim: AtomicFileTests.AWriteWaitsForAReaderThatBlocksDeleteSharingAndThenReplacesTheFile holds a FileShare.ReadWrite reader during the commit. It fails before the fix (Dns.Common.Tests Failed 1 of 13) and passes after.

Fix: on Windows, File.Replace is retried on a sharing violation (HResult 0x80070020/0x80070021/0x80070497), at most 20 times 50 ms apart. The target keeps its ACL. Unix is unchanged.

Results: Windows Dns.Common.Tests 356/356, Webhooks.Tests 38/38; the whole solution is green on Linux. Closes when the epic branch merges into develop.

Done on `feature/8-windows-test-suite` (99f6d568). **Could a live settings write on Windows fail before the fix? Yes, briefly.** A configuration provider with `reloadOnChange` re-reads the runtime file shortly after every write. While its read handle is open without delete sharing, `File.Replace` in `StagedFile.Commit` fails. So a settings write that lands during the previous write's reload, or during an operator's quick second write, could fail. Ninlil's own readers use `File.ReadAllText` and close at once, and writers are serialised by `AtomicFile.GetPathLock`. Evidence on Lofnheim: `AtomicFileTests.AWriteWaitsForAReaderThatBlocksDeleteSharingAndThenReplacesTheFile` holds a `FileShare.ReadWrite` reader during the commit. It fails before the fix (Dns.Common.Tests Failed 1 of 13) and passes after. Fix: on Windows, `File.Replace` is retried on a sharing violation (HResult 0x80070020/0x80070021/0x80070497), at most 20 times 50 ms apart. The target keeps its ACL. Unix is unchanged. Results: Windows Dns.Common.Tests 356/356, Webhooks.Tests 38/38; the whole solution is green on Linux. Closes when the epic branch merges into develop.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
lantea-one/ninlil#13
No description provided.