Add retry for os.rename in atomicFileWriter
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start in atomicwriter/atomicwriter.go around line 155, where os.rename is called, and review the surrounding atomicFileWriter flow. Use the provided Windows reproduction with Microsoft Defender enabled to verify that transient rename failures are retried and that successful writes still complete without errors.
Written by the indexing model from the issue text.
Description
Problem: Updating files using atomicFileWriter can fail during rename on Windows, due to AV software holding the file handle.
Reproduction steps:
Run this simple program on Windows
package main
import (
"fmt"
"log"
//"time"
"github.com/moby/sys/atomicwriter"
)
func main() {
data := []byte(`{
"builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false
}`)
var count uint64
fmt.Println("starting the test")
for {
count++
//time.Sleep(50 * time.Millisecond)
err := atomicwriter.WriteFile("test_daemon.json", data, 0o644)
if err != nil {
log.Fatalf("write failed after %d iterations: %v\n", count, err)
}
}
}
It will fail with below error after 1 or 2 minutes:
2026/04/24 12:16:24 write failed after 7807 iterations: rename C:\Users\azureuser\tmp\.tmp-test_daemon.json854562021 C:\Users\azureuser\tmp\test_daemon.json: Access is denied.
exit status 1
I just have Microsoft Defender on this system with default configuration.
Some environments (finance sector customers) have strict security policy where customers cannot exclude folders from AV scans.
Adding a retry around os.rename at https://github.com/moby/sys/blob/main/atomicwriter/atomicwriter.go#L155 can avoid this transient rename failure.
- Dominant language
- Go
- Stars
- 100
- Forks
- 61
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from moby/sys
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
repowise-dev/repowise#2966 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
blinklabs-io/dingo#4937 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
getkin/kin-openapi#1284 ·
Maintainers usually reply within 1 day
-
software-development-practices software-development-practices:nist-ssdf
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
githubnext/gh-aw-cao#15860 ·
Maintainers usually reply within 1 day