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

Using the bundler via API doesn't terminate all workers #1723

Closed
tripodsan opened this issue Jul 13, 2018 · 7 comments
Closed

Using the bundler via API doesn't terminate all workers #1723

tripodsan opened this issue Jul 13, 2018 · 7 comments
Labels

Comments

@tripodsan
Copy link
Contributor

tripodsan commented Jul 13, 2018

🐛 bug report

We have test suite in parcel-plugin-htl that uses the Bundler via API to test the plugin. The testrunner doesn't complete if running more than 1 test. I think this has something to do with the Workers used in Bundler not being shutdown correctly.

🎛 Configuration (.babelrc, package.json, cli command)

🤔 Expected Behavior

Tests complete without error and test runner terminates.

😯 Current Behavior

Test complete without error; but test runner hangs.

💁 Possible Solution

when using a new farm instead of the shared one, it works:

Bundler.js
...
-    this.farm = WorkerFarm.getShared(this.options);
+    this.farm = new WorkerFarm(this.options);

🔦 Context

Without this fixed, our plugin tests don't complete and we have to disable them on the CI.

💻 Code Sample

https://github.com/adobe/parcel-plugin-htl/blob/master/test/unit/testHTML.js#L66

🌍 Your Environment

Software Version(s)
Parcel parcel-bundler": "^1.9.6"
Node 8.11.3
npm/Yarn npm 6.1.0
Operating System macOS
@devongovett
Copy link
Member

hmm it should stop unless there is a watcher. Just looked in the parcel core tests and it adds the --exit argument to mocha. See https://mochajs.org/#--exit----no-exit.

@tripodsan
Copy link
Contributor Author

@devongovett well, but I think this is just a workaround. parcel should cleanup all the workers when used via API. the hanging tests indicate that it doesn't do so.

as mentioned above, using a ne WorkerFarm instead of the shared one solves the problem.

@devongovett devongovett reopened this Jul 18, 2018
@devongovett
Copy link
Member

hmm not sure what's going on here then. perhaps because there are multiple bundler instances in the tests something weird is happening.

@DeMoorJasper
Copy link
Member

The workerfarm ends asynchronously, so perhaps you could try something like await bundler.stop()?
I've experienced and fixed a lot of issues with killing workers, but it should work.

@tripodsan
Copy link
Contributor Author

@DeMoorJasper you're correct. when I change this to await this.stop() it works:

$ git diff
diff --git a/src/Bundler.js b/src/Bundler.js
index dd7d173..d02c93e 100644
--- a/src/Bundler.js
+++ b/src/Bundler.js
@@ -329,7 +329,7 @@ class Bundler extends EventEmitter {

       // If not in watch mode, stop the worker farm so we don't keep the process running.
       if (!this.watcher && this.options.killWorkers) {
-        this.stop();
+        await this.stop();
       }
     }
   }

@tripodsan
Copy link
Contributor Author

tripodsan commented Jul 19, 2018

I'll create a PR. see #1760

@DeMoorJasper
Copy link
Member

Merged! Thanks :)

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

3 participants