【问题标题】:Ansible: git clone fails with "fatal: Out of memory, realloc failed"Ansible: git clone 失败并显示“致命:内存不足,重新分配失败”
【发布时间】:2022-10-20 11:55:03
【问题描述】:

我将 Ansible 与 Windows 主机 (VM) 一起使用。 我正在尝试git clone 一个大的内容(实际上使用git lfs)。总共大约15Go

我正在使用git for windows (https://github.com/git-for-windows/git/releases/tag/v2.37.2.windows.2)。

我有以下 Ansible 任务:

- name: Clone repository
  ansible.windows.win_command: >
    <path/to/git.exe> clone <git-repo>

问题是它总是因错误而失败:

fatal: Out of memory, realloc failed

我尝试增加 Windows VM 内存,或使用git config 设置,如几篇文章中所述,例如:

但是这些解决方案都不适合我。它总是在相同的点上失败:

"Filtering content:  48% (440/902), 2.11 GiB | 6.70 MiB/s",
"fatal: Out of memory, realloc failed",
"Error downloading object: xxxxxxx: Smudge error: Error reading from media file: write /dev/stdout: The pipe is being closed.: write /dev/stdout: The pipe is being closed.",
"",
"Errors logged to 'xxxx.log'.",
"Use `git lfs logs last` to view the log.",
"warning: Clone succeeded, but checkout failed.",
"You can inspect what was checked out with 'git status'",
"and retry with 'git restore --source=HEAD :/'"

奇怪的是,这个错误只在使用 Ansible 时发生。如果我连接到虚拟机并手动运行完全相同的git clone 命令,一切都会顺利进行。

你有什么想法可以帮助我吗?谢谢

【问题讨论】:

  • 您可以尝试将其拆分为两个步骤:(1) 在没有安装 LFS 的情况下进行克隆,以便获得“指针文件”而不是真实文件(使用 --no-checkout 跳过无用的签出)。 (2) 安装 LFS 并将其插入下载真实文件。可能首先单独使用--no-checkout 可能会避免该问题,但分两步执行意味着Git 可以在没有Git-LFS 包装器占用内存的情况下运行,然后Git-LFS 可以使用内存较少的Git 操作运行.
  • 这是一个纯粹的 git checkout 问题。删除 ansible 标签。
  • 我知道问题来自git checkout。但是,它只发生在我使用 Ansible 时。我直接在主机上运行时没有这个问题

标签: windows git ansible git-lfs


【解决方案1】:

我在类似的情况下经历了同样的行为。我试图为最初超过 100GB 并且还包含 LFS 文件的存储库进行参考克隆。只有在尝试通过 Ansible 的 win_shell 执行克隆时才会看到内存不足。

对我有用的是使用 Ansible win_shell 模块并将 MaxMemoryPerShellMB 增加到足够大的值。我通过将内存加倍直到它大于默认值但小于或等于我机器的实际内存限制来计算出这个值。

包括成功解决此问题所需的任务的 sn-p:

---
- name: Increase MaxMemoryPerShellMB
  win_shell: 'Set-Item WSMan:localhostShellMaxMemoryPerShellMB <value>'

- name: Clone the repository
  win_shell: '<git clone command>'
  args:
    executable: cmd

此外,如果您的用例可能,我建议您跳过 LFS 文件的克隆,然后获取您需要的文件。请参阅“How to clone/pull a git repository, ignoring LFS?”中的git config 命令。这很微妙,但答案似乎表明 GIT_LFS_SKIP_SMUDGE 变量对于 Windows 已过时。我仍在尝试为此找到合适的文档。

我希望这可以帮助你!

【讨论】:

    猜你喜欢
    • 2023-03-10
    • 1970-01-01
    • 2011-11-28
    • 2018-08-20
    • 2023-02-02
    • 1970-01-01
    • 2016-12-19
    • 2014-11-23
    • 2019-06-28
    相关资源
    最近更新 更多