卡住不活动的 msbuild.exe 进程、锁定 Stylecop.dll、Nuget AccessViolationException 和 CI 构建相互冲突的奥秘 [英] The mystery of stuck inactive msbuild.exe processes, locked Stylecop.dll, Nuget AccessViolationException and CI builds clashing with each other

查看:25
本文介绍了卡住不活动的 msbuild.exe 进程、锁定 Stylecop.dll、Nuget AccessViolationException 和 CI 构建相互冲突的奥秘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

观察:

  • 在我们的 Jenkins 构建服务器上,我们看到许多 msbuild.exe 进程(约 100 个)在作业完成后挂起,内存使用量约为 20mb,CPU 活动为 0%.

  • On our Jenkins build server, we were seeing lots of msbuild.exe processes (~100) hanging around after job completion with around 20mb memory usage and 0% CPU activity.

使用不同版本的 stylecop 构建间歇性失败:

Builds using different versions of stylecop were intermittently failing:

workspacepackagesStyleCop.MSBuild.4.7.41.0 oolsStyleCop.targets(109,7):错误 MSB4131:StyleCopTask"任务不支持ViolationCount"参数.验证该参数是否存在于任务中,并且它是一个可获取的公共实例属性.

Nuget.exe 间歇性地退出并出现以下访问冲突错误 (0x0000005):

Nuget.exe was intermittently exiting with the following access violation error (0x0000005):

<代码>.workspace.nuget uget install .workspacepackages.config -o .workspacepackages"以代码 -1073741819 退出.

.workspace.nuget uget install .workspacepackages.config -o .workspacepackages" exited with code -1073741819.

MsBuild 通过 Jenkins Matrix 作业以下列方式启动,并启用了BuildInParallel":

MsBuild was launched in the following way via a Jenkins Matrix job, with 'BuildInParallel' enabled:

    `msbuild /t:%Targets% /m
    /p:Client=%Client%;LOCAL_BUILD=%LOCAL_BUILD%;BUILD_NUMBER=%BUILD_NUMBER%;
    JOB_NAME=%JOB_NAME%;Env=%Env%;Configuration=%Configuration%;Platform=%Platform%;
    Clean=%Clean%; %~dp0\_JenkinsBuild.proj`

推荐答案

经过很多的挖掘和尝试各种事情都没有效果,我最终创建了一个新的最小解决方案,它重现了几乎没有其他事情发生的问题.这个问题原来是由 msbuild 的多核并行化 - 'm' 参数引起的.

After a lot of digging around and trying various things to no effect, I eventually ended up creating a new minimal solution which reproduced the issue with very little else going on. The issue turned out to be caused by msbuild's multi-core parallelisation - the 'm' parameter.

  • m"参数告诉 msbuild 生成节点",这些节点会在构建结束后保持活动状态,然后被新构建重新使用!
  • StyleCop 'ViolationCount' 错误是由给定的构建重新使用另一个构建工作区中旧版本的 stylecop.dll 引起的,其中不支持 ViolationCount.这很奇怪,因为 CI 工作区只包含新版本.似乎一旦将 StyleCop.dll 加载到给定的 MsBuild 节点中,它将为下一次构建保持加载状态.我只能假设这是因为 StyleCop 将某种单例加载到节点进程中?这也解释了构建之间的文件锁定.
  • nuget 访问冲突崩溃现在已经消失(没有其他更改),因此显然与上述节点重用问题有关.
  • 由于m"参数默认为内核数 - 我们看到 24 个 msbuild 实例在我们的构建服务器上为给定作业创建.
  • The 'm' parameter tells msbuild to spawn "nodes", these will remain alive after the build has ended, and are then re-used by new builds!
  • The StyleCop 'ViolationCount' error was caused by a given build re-using an old version of the stylecop.dll from another build's workspace, where ViolationCount was not supported. This was odd, because the CI workspace only contained the new version. It seems that once the StyleCop.dll was loaded into a given MsBuild node, it would remain loaded for the next build. I can only assume this is because StyleCop loads some sort of singleton into the nodes processs? This also explains the file-locking between builds.
  • The nuget access violation crash has now gone (with no other changes), so is evidently related to the above node re-use issue.
  • As the 'm' parameter defaults to the number of cores - we were seeing 24 msbuild instances created on our build server for a given job.

以下帖子很有帮助:

修复:

  • set MSBUILDDISABLENODEREUSE=1 行添加到启动 msbuild 的批处理文件中
  • 使用 /m:4/nr:false 启动 msbuild
  • nr"参数告诉 msbuild 不要使用节点重用" - 因此 msbuild 实例在构建完成后关闭并且不再相互冲突 - 导致上述错误.
  • m"参数设置为 4 以阻止每个作业产生过多节点
  • Add the line set MSBUILDDISABLENODEREUSE=1 to the batch file which launches msbuild
  • Launch msbuild with /m:4 /nr:false
  • The 'nr' paremeter tells msbuild to not use "Node Reuse" - so msbuild instances are closed after the build is completed and no longer clash with each other - resulting in the above errors.
  • The 'm' parameter is set to 4 to stop too many nodes spawning per-job

这篇关于卡住不活动的 msbuild.exe 进程、锁定 Stylecop.dll、Nuget AccessViolationException 和 CI 构建相互冲突的奥秘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆