Skip to content

Race condition when loading starter kits #629

Closed
@tburny

Description

@tburny

I am using Pattern Lab Node v2.7.2 on Linux, with Node v4.7.0, using the Grunt Edition.

See also pattern-lab/edition-node-grunt#12

Expected Behavior

Starter Kits are always loaded completely when running starterkit_manager.loadstarterkit() via

  1. core/scripts/postinstall.js
  2. gulp patternlab:loadstarterkit --kit=yourkit
  3. grunt patternlab:loadstarterkit --kit=yourkit

The output is

====[ Pattern Lab / Node - v2.7.2 ]====

Running "patternlab:loadstarterkit" (patternlab) task
Attempting to load starterkit from /home/tobi/tmp/edition-node-grunt/node_modules/starterkit-thymol-demo/dist
Deleting contents of ./source/ prior to starterkit load.
starterkit starterkit-thymol-demo loaded successfully.

Done.
Actual Behavior

The command line shows a success message, but only in case 1. and 2. the StarterKit files are actually copied.

The reason is that starterkit_manager uses the ansynchnous variant of fs.copy(src, dest, callback). Typically a starterkit is < ~1MB of files, while modern SSD's have speeds of 300+ GB/s. Thus copying the whole starterkit takes only a few milliseconds at most.

In postinstall.js(Method 1) there is a plugin discovery with synchronous file system access, which just takes enough time to complete copying the StarterKit.

With gulp (method 2), the behaviour seems to be similar. Additionally there is some async handling in gulp via done(). Presumably similar to Method 1 shutting down the gulp process also takes enough time.

Lastly when using grunt, the process finishes before the callback is even executed (i.e. copying the files takes longer than processing the remaining code, which only consists of method returns).

The output is

====[ Pattern Lab / Node - v2.7.2 ]====

Running "patternlab:loadstarterkit" (patternlab) task
Attempting to load starterkit from /home/tobi/tmp/edition-node-grunt/node_modules/starterkit-thymol-demo/dist
Deleting contents of ./source/ prior to starterkit load.

Done.

As you can see the starterkit starterkit-thymol-demo loaded successfully. is missing.

Steps to Reproduce

Try to install a starterkit via edition-node-grunt. By default the source folder will stay empty.

Now, after the line grunt.registerTask('patternlab') insert const done = this.async(); into the callback function. Likewise, add

    setTimeout(function () {
      done();
    }, 10000);

at the very end of the callback function.

Now the source files are copied from the StarterKit successfully.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions