卡住的非活动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

查看:122
本文介绍了卡住的非活动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:

workspace\packages\StyleCop.MSBuild.4.7.41.0\tools\StyleCop.targets(109,7): error MSB4131: The "ViolationCount" parameter is not supported by the "StyleCopTask" task. Verify the parameter exists on the task, and it is a gettable public instance property.

workspace\packages\StyleCop.MSBuild.4.7.41.0\tools\StyleCop.targets(109,7): error MSB4131: The "ViolationCount" parameter is not supported by the "StyleCopTask" task. Verify the parameter exists on the task, and it is a gettable public instance property.

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

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

.\workspace\.nuget\nuget install .\workspace\packages.config -o .\workspace\packages" exited with code -1073741819.

.\workspace\.nuget\nuget install .\workspace\packages.config -o .\workspace\packages" 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\_Jenkins\Build.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'错误是由给定的版本重新使用另一个版本的工作空间中不支持ViolationCount的stylecop.dll的旧版本引起的.这很奇怪,因为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.

以下帖子很有帮助:

  • msbuild.exe staying open, locking files
  • http://www.hanselman.com/blog/FasterBuildsWithMSBuildUsingParallelBuildsAndMulticoreCPUs.aspx
  • http://stylecop.codeplex.com/discussions/394606
  • https://github.com/Glimpse/Glimpse/issues/115
  • http://msdn.microsoft.com/en-us/library/vstudio/ms164311.aspx

解决方法:

  • 将行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天全站免登陆