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

Exit when STDIN closes #1004

Closed
wants to merge 3 commits into from
Closed

Conversation

rzane
Copy link

@rzane rzane commented Mar 15, 2018

This PR adds a new flag to the watch command that instructs Parcel to exit when STDIN closes. This is consistent with the behavior in Webpack and Brunch.

Here's a really clear synopsis from this Brunch issue:

I would like to automatically run parcel watch as part of my application but, when my application shuts down, the parcel process persists and continue running. I have observed that my application does close STDIN, however, brunch watch is not checking if STDIN was closed or not. These two lines solve the issue:

process.stdin.on('end', () => process.exit(0));
process.stdin.resume();

I am running on the Erlang VM which does not expose the OS Process API as node.js does (in fact, neither does the Java VM last time I checked. It is common for VMs to not expose those operations as it is hard to provide an unified API across multiple OS and hardware).

As such, it is common for Unix processes to exit when STDIN closes.

Relevant links:

that the program will exit when STDIN closes. This is consisent with the
behavior in Webpack and Brunch.
@rzane
Copy link
Author

rzane commented Mar 15, 2018

Force pushed to trigger a CI rebuild. I suspect that the Node 6 tests are flaking.

@davidnagli
Copy link
Contributor

@rzane Ya, we have some flakiness issues with Node 6 tests

@codecov-io
Copy link

codecov-io commented Mar 19, 2018

Codecov Report

Merging #1004 into master will increase coverage by 3.11%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1004      +/-   ##
==========================================
+ Coverage   89.27%   92.38%   +3.11%     
==========================================
  Files          69       69              
  Lines        3393     2680     -713     
==========================================
- Hits         3029     2476     -553     
+ Misses        364      204     -160
Impacted Files Coverage Δ
src/assets/CSSAsset.js 82.6% <0%> (-7.83%) ⬇️
src/visitors/matches-pattern.js 94.73% <0%> (-5.27%) ⬇️
src/transforms/uglify.js 69.56% <0%> (-4.35%) ⬇️
src/assets/JSAsset.js 92.77% <0%> (-1.89%) ⬇️
src/WorkerFarm.js 91.93% <0%> (-1.62%) ⬇️
src/transforms/babel.js 93.63% <0%> (-1.51%) ⬇️
src/transforms/postcss.js 93.33% <0%> (-1.22%) ⬇️
src/assets/RustAsset.js 90.47% <0%> (-1.2%) ⬇️
src/utils/getTargetEngines.js 96.15% <0%> (-0.48%) ⬇️
src/utils/urlJoin.js 100% <0%> (ø) ⬆️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7f9c64...5177a33. Read the comment docs.

Copy link
Contributor

@davidnagli davidnagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@devongovett
Copy link
Member

I guess I don't understand why this option is necessary. Could you give me more details about your setup? How are you running parcel?

@rzane
Copy link
Author

rzane commented Mar 20, 2018

I am writing a Phoenix application. Phoenix is a web framework written in Elixir.

Elixir doesn't have a way to send a kill signal to a process. It is common for VMs to not expose those operations as it is hard to provide an unified API across multiple OS and hardware. As such, it is quite common for UNIX tools to exit when STDIN closes.

Specifically, my problem is that Phoenix provides the ability to start an asset bundler when the server starts. And, when the Phoenix server shuts down, it closes STDIN. Unfortunately, because parcel doesn't exit when STDIN closes, parcel doesn't die. It just stays alive.

As mentioned in the original description, Webpack and Brunch currently offer this functionality.

@devongovett
Copy link
Member

hmm, ok. Is there any reason to not make this default behavior instead of adding an option?

@rzane
Copy link
Author

rzane commented Mar 20, 2018

Yes. If you run parcel with --stdin, then press Ctrl+z to suspend, then bg to run in the background, parcel will exit. Since this could affect the workflow of current parcel users, it's probably wise to put this functionality under a flag.

Here's the issue report of that specific problem: brunch/brunch#998.

@dparnell
Copy link

I've written a little plugin for parcel that causes it to die when stdin is closed.
You can get it here: https://github.com/dparnell/parcel-plugin-stdin

@rzane
Copy link
Author

rzane commented Jun 15, 2018

I think @dparnell's plugin is probably an adequate and simple solution for this specific problem.

@devongovett
Copy link
Member

You could also make a small wrapper script like this:

#!/bin/sh
"$@" &
pid=$!
while read line ; do
  :
done
kill -KILL $pid

https://hexdocs.pm/elixir/Port.html#module-zombie-processes

I'm going to close this since it is possible to work around. I don't think this is Parcel's problem.

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

Successfully merging this pull request may close these issues.

6 participants