Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Add retry for os.rename in atomicFileWriter

オープン
#219 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
go
領域
tooling

調査の方向性

os.rename が呼び出されている atomicwriter/atomicwriter.go の 155 行目付近から始め、周辺の atomicFileWriter フローを確認します。Microsoft Defender を有効にした、提供されている Windows の再現手順を使用して、一時的な rename 失敗が再試行され、成功した書き込みが引き続きエラーなしで完了することを検証します。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Go
スター
102
フォーク
62
平均マージ
3分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

moby/sys のほかの issue

moby/sys の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。