Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition when loading starter kits #629

Closed
tburny opened this issue Feb 24, 2017 · 0 comments
Closed

Race condition when loading starter kits #629

tburny opened this issue Feb 24, 2017 · 0 comments
Assignees
Labels

Comments

@tburny
Copy link

tburny commented Feb 24, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant