Retry with bounded backoff
terminal / powershell
$max = 3; $delay = 300
for ($attempt = 1; $attempt -le $max; $attempt++) {
try { [IO.File]::WriteAllText($path, $content); break }
catch [IO.IOException] {
if ($attempt -eq $max) { Write-Verbose "Skipped (in use): $path"; break }
Start-Sleep -Milliseconds $delay; $delay *= 2
}
}Judgement, not just mechanics
- Exponential ceiling: 300 ms → 600 ms → 1.2 s caps total wait at ~2 seconds; a busy file next sign-in is free to win next time.
- Distinguish violation from authorization: IOException from sharing-lock is transient; from ACL is permanent — retrying the latter is just theatre that a log-reader can't un-watch.
- Delete-skip balance: for cleanup-scoped tasks, skipping is correct on first lock, with a counter reported. For authoritative writes (journals), retries before the entry are warranted — journal-integrity outweighs amenity.
Tools get trusted on weird days: the test is whether their logs let you say precisely which bytes were skipped, at which attempt, and why — rather than “something failed somewhere.”