psake / psake/PowerShellBuild

Windows builds hang when the HEAD commit message is large (Invoke-Git deadlock)

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

还没有人认领这个 Issue。

bug
主要语言
PowerShell
星标
145
派生
27
平均合并
10 小时 16 分钟
30 天内合并 PR
34

描述

Part of #120. Found while verifying the #162 merge.

Symptom

On Windows, Set-BuildEnvironment hangs forever when the HEAD commit message is large. Nothing
is printed, no error, no timeout — the build never starts.

This is currently happening on main. The push-triggered CI run for 9720cb7 hung both Windows
legs for 27+ minutes with zero output (ubuntu and macOS passed); I cancelled it. Every local
./build.ps1 on Windows hangs the same way, because build.ps1 calls Set-BuildEnvironment -Force before Invoke-psake.

Root cause

BuildHelpers\Invoke-Git (2.0.16) redirects both output streams and then waits for the process
to exit before reading them:

$pinfo.RedirectStandardError  = $RedirectStandardError   # $true
$pinfo.RedirectStandardOutput = $RedirectStandardOutput  # $true
...
$null = $p.Start()
$p.WaitForExit()                        # <-- blocks here
...
$stdout = $p.StandardOutput.ReadToEnd() # <-- never reached

When git writes more than the pipe buffer holds, git blocks waiting for someone to drain the
pipe, and Invoke-Git blocks waiting for git to exit. Neither can proceed. It is the textbook
WaitForExit-before-ReadToEnd deadlock described in the
ProcessStartInfo.RedirectStandardOutput remarks.

Get-BuildVariable calls it as Invoke-Git log --format=%B -n 1 <sha> to populate
$env:BHCommitMessage, so the payload is the full commit message body.

Reproduction

Measured on Windows 11, PowerShell 7.6.4, BuildHelpers 2.0.16, against real commits on main:

Commit Message size Result
f726f48 2617 bytes returns
64b7207 5498 bytes returns
9720cb7 5757 bytes hangs
Import-Module BuildHelpers
Invoke-Git -Arguments 'log --format=%B -n 1 9720cb7'   # never returns on Windows

Linux and macOS have a larger pipe buffer and do not hit the threshold at these sizes, which is
why only the Windows legs hang.

Why CI did not catch it before merge

On a pull_request event, GitHub checks out a synthetic merge commit whose message is short
(Merge <sha> into <sha>). The real squash message only becomes HEAD on the push to main.
Every PR will be green and then hang main if its squashed body is large enough.

This repository writes long PR bodies and squash-merges them verbatim, so the trigger is not
exotic — it is the house style. #163 and #165 both have bodies over the threshold today.

Consumer impact

This is not only a repo-internal problem. Initialize-PSBuild calls Set-BuildEnvironment, so
any consumer building on Windows hangs when their own HEAD commit message crosses the threshold.
A hang with no output is a bad failure mode to ship at 1.0.0.

Options

  1. Stop passing the payload through Invoke-Git. Populate $env:BHCommitMessage ourselves
    before calling Set-BuildEnvironment, or truncate it. Narrow, immediate, ours to control
  2. Fix upstream. Read the streams asynchronously (BeginOutputReadLine, or ReadToEnd
    before WaitForExit) and PR it to BuildHelpers, then raise the RequiredModules floor once
    released. Correct fix, slowest path
  3. Trim squash commit messages at merge time. Pure process change, no code — but it depends
    on every future merge remembering, and it does nothing for consumers
  4. Drop the BuildHelpers dependency for this variable. Largest change; worth naming only
    because #120 already asks what 1.0.0 should depend on

Options 1 and 2 are not exclusive: 1 unblocks now, 2 fixes it for everyone.

Immediate mitigation

Until this is fixed, squash-merge with a short commit body on this repo. The full PR
description stays on the pull request either way.

Done when

./build.ps1 and Windows CI complete regardless of HEAD commit message size, with a regression
test covering a message larger than the pipe buffer.

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 build.ps1 和 Set-BuildEnvironment 路径开始,然后检查 BuildHelpers\Invoke-Git 和 Get-BuildVariable,以确认如何读取提交消息。在 Windows 上使用 Invoke-Git log --format=%B -n 1 9720cb7 重现挂起,并在从列出的缓解选项中进行选择之前查看 #120。完成意味着对于较大的 HEAD 消息,./build.ps1 和 Windows CI 都能完成,并且有一个覆盖大于管道缓冲区的消息的回归测试。

由索引模型根据 Issue 内容生成。

评估

技术栈
git, powershell
领域
build-system, ci-cd, tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
活跃
描述清晰度
基本清楚
新手友好度
50/100

把新 issue 发到你的邮箱

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