Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Add retry for os.rename in atomicFileWriter

Open
#219 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
go
Domain
tooling

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from moby/sys

All issues in moby/sys

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.