Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Add retry for os.rename in atomicFileWriter

未关闭
#219 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
go
领域
tooling

调研方向

从 atomicwriter/atomicwriter.go 第 155 行附近开始,该处调用了 os.rename,并检查周围的 atomicFileWriter 流程。使用提供的、已启用 Microsoft Defender 的 Windows 复现环境,验证临时重命名失败会进行重试,并且成功的写入仍能无错误地完成。

由索引模型根据 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
星标
103
派生
64
平均合并
6 分钟
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

moby/sys 的其他 Issue

查看 moby/sys 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。