javascriptnode.jsgruntjslibxml-js

Grunt "force stops" in the middle of a task


I have made a custom grunt task, that embeds filtered files within Visual Studio C# project file (*.csproj).

The task (vsembed) is part of a custom build system I am developing by using grunt.

Gruntfile.js; vsembed.js

The problem is a weird one, though...

TL;DR

If I run specific targets' task - success. If I run for all targets at once - quits with no errors.

Long version.

If I run the task specifying a target (so it runs once) it completes successfully, like so:

C:\StoneOS>grunt vsembed:StoneOS.Modules.Pages.views --debug --verbose
Initializing
Command-line options: --debug=1, --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt_tasks" tasks.
Loading "vsembed.js" tasks...OK
+ vsembed, vsrembed

Registering "grunt-msbuild" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Loading "msbuild.js" tasks...OK
+ msbuild

Registering "grunt-contrib-compass" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Loading "compass.js" tasks...OK
+ compass

Registering "grunt-contrib-copy" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Loading "copy.js" tasks...OK
+ copy

Registering "grunt-contrib-clean" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Loading "clean.js" tasks...OK
+ clean
Loading "Gruntfile.js" tasks...OK
+ assets, default, development, embed, release, rembed

Running tasks: vsembed:StoneOS.Modules.Pages.views

Running "vsembed:StoneOS.Modules.Pages.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Pages\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Pages", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\websocket.cshtml', 'views\\websocket\\script.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\websocket.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\websocket\script.cshtml"/>
Included 2 files.
Written 3861 bytes to: C:\StoneOS\src\StoneOS.Modules.Pages\StoneOS.Modules.Pages.csproj

Done, without errors.

If I run the task for the whole group, it completes sometimes 3, sometimes 4 targets, sometimes quits in middle of completing 4th. Here is an output of latest run, where it stops at the same task as shown in the specific target example above, which is 4th task.

C:\StoneOS>grunt vsembed --debug --verbose
Initializing
Command-line options: --debug=1, --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Initializing config...OK

Registering "grunt_tasks" tasks.
Loading "vsembed.js" tasks...OK
+ vsembed, vsrembed

Registering "grunt-msbuild" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-msbuild\package.json...OK
Loading "msbuild.js" tasks...OK
+ msbuild

Registering "grunt-contrib-compass" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-compass\package.json...OK
Loading "compass.js" tasks...OK
+ compass

Registering "grunt-contrib-copy" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-copy\package.json...OK
Loading "copy.js" tasks...OK
+ copy

Registering "grunt-contrib-clean" local Npm module tasks.
Reading C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Parsing C:\StoneOS\node_modules\grunt-contrib-clean\package.json...OK
Loading "clean.js" tasks...OK
+ clean
Loading "Gruntfile.js" tasks...OK
+ assets, default, development, embed, release, rembed

Running tasks: vsembed

Running "vsembed" task
[D] Task source: grunt_tasks\vsembed.js

Running "vsembed:StoneOS.Modules.Authentication.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Authentication\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Authentication", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\login.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\login.cshtml"/>
Included 1 files.
Written 4605 bytes to: C:\StoneOS\src\StoneOS.Modules.Authentication\StoneOS.Modules.Authentication.csproj

Running "vsembed:StoneOS.Modules.Installer.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Installer\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Installer", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\introduction.cshtml',
  'views\\layouts\\installer.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\introduction.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\layouts\installer.cshtml"/>
Included 2 files.
Written 3470 bytes to: C:\StoneOS\src\StoneOS.Modules.Installer\StoneOS.Modules.Installer.csproj

Running "vsembed:StoneOS.Modules.Main.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Main\.views exists in config...OK
File: [no files]
Options: project="C:\\StoneOS\\src\\StoneOS.Modules.Main", directories=["views"], extensions=".cshtml"
Found embeddable files within filesystem:  [ 'views\\test.cshtml',
  'views\\layouts\\logo.cshtml',
  'views\\layouts\\main.cshtml',
  'views\\errors\\403.cshtml',
  'views\\errors\\404.cshtml' ]
Acceptable item: <EmbeddedResource Include="views\test.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\layouts\logo.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\layouts\main.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\errors\403.cshtml"/>
Acceptable item: <EmbeddedResource Include="views\errors\404.cshtml"/>
Included 5 files.
Written 7090 bytes to: C:\StoneOS\src\StoneOS.Modules.Main\StoneOS.Modules.Main.csproj

Running "vsembed:StoneOS.Modules.Pages.views" (vsembed) task
[D] Task source: grunt_tasks\vsembed.js
Verifying property vsembed.StoneOS\.Modules\.Pages\.views exists in config...OK
File: [no files]

With "force quits" I mean, that, as you can see above, it ends with File: [no files] which is a native grunt feature when running in verbose mode. It always is followed by Options as seen in those three target outputs above.

It feels as if it happens after reaching a timeout, or some memory limit.

If I remove some XML based tasks, the task will complete (though, loses all purpose), so I assume the problem might be with libxmljs. What makes me only assume that, is the last output- where even the grunt native output is cut off.

Running Windows 7 x64, node v0.10.29, npm 1.4.14, grunt-cli v0.1.13, grunt v0.4.5.

I'm really out of clues here...

What could cause the problem where a single target executes, but multiple sequential "silently fail"?


Solution

  • Quite interestingly, starting to debug this a little more, I stumbled on node-memwatch.

    Adding some HeapDiff checks made my tasks to run, so, it looked to be related to memory/GC.

    Removing HeapDiff checks, adding manual GC clears with global.gc(); and running grunt with --expose-gc solved the problem.

    Sadly, but now from a simple grunt vsembed I had to install grunt and grunt-cli locally (instead of -g), and run it with node --expose-gc node_modules\grunt-cli\bin\grunt vsembed.

    Well, anyways, got it resolved.