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

Handle process stdin #3323

Closed
wants to merge 5 commits into from
Closed

Handle process stdin #3323

wants to merge 5 commits into from

Conversation

Kjir
Copy link

@Kjir Kjir commented Oct 25, 2017

This PR continues the work started in #1754 so that it might be merged.

I rebased the changes on top of master (which should fix the test errors, hopefully) and I created the helper in react-dev-utils as suggested in the previous code review.

I tested that it still works with a very simple python program:

import time

time.sleep(10)

After 10 seconds the program does actually quit, both when watching test and when running the dev server.

I am not sure there is a suitable way of adding a test for this, if I receive some suggestions about this I will gladly implement them!

Fixes #1753

@Timer
Copy link
Contributor

Timer commented Oct 27, 2017

Great, thank you!

This doesn't seem to play well with our CI; could you please look into why and fixing that?

@Kjir
Copy link
Author

Kjir commented Oct 27, 2017

To be honest it looks to me like this is a pre-existing condition which is shared between many of the latest pull request. Even on master I see the same failure on appveyor: https://ci.appveyor.com/project/gaearon/create-react-app-a3khu/build/1.0.1675/job/appdu6xgv2it578i

I will look into it to see if I can untangle it, but I doubt it has anything to do with the changes introduced here. I will let you know!

@Kjir
Copy link
Author

Kjir commented Oct 27, 2017

Looking more attentively I could replicate the issue on my machine and I will now address it! But the problem I have is the one on Travis and not the one on appveyor...

@Kjir
Copy link
Author

Kjir commented Nov 4, 2017

After a lot of head scratching, I found out what the problem is thanks to this question: https://unix.stackexchange.com/questions/3886/difference-between-nohup-disown-and

What happens is that when bash puts a process as a background job, it will halt that program as soon as it tries to read from STDIN.

What this means is that with this patch will make it harder to run npm start as a background job, requiring you to give it some input (e.g.: npm start </dev/zero &). I do not know whether this affects someone or it doesn't, because I don't know if people use the webserver this way.

@Kjir
Copy link
Author

Kjir commented Nov 4, 2017

Just to be on the safe side, I also added a note in the Troubleshooting section.

@Kjir
Copy link
Author

Kjir commented Nov 4, 2017

There could be an alternative: this functionality is only enabled through a flag that we would provide to npm start. While it goes against the general policy of not having flags and configurations, it is also true that the "Listen to stdin to close" is only needed when used in combination with other tools — namely the Phoenix framework.

Since this decision is not technical I await further insights and will eventually change my PR to go in this other direction, if deemed preferable.

@Kjir
Copy link
Author

Kjir commented Nov 4, 2017

In all this I forgot about Windows!
At this point the only viable option is to add the flag to npm start, so that people using Phoenix can fulfill the requirement without disrupting everyone else. The flag is not meant to be used in normal, manual situations, so I think it is an acceptable compromise.

(Sorry about the numerous comments)

The kitchensink e2e tests were failing because in those tests the
`npm start` command is sent to the background. The shell will then halt
any background job that tries to read from the standard input, and since
we are watching standard input to determine if we should exit or not the
dev server would immediately exit.

The workaround is to provide run the dev-server as
`npm start </dev/zero &` instead, which provides a different standard
input that will not close immediately. This, alas, doesn't work on
Windows and might change the expected behaviour for some people that are
used to start the dev-server as a background job.

For this reason a --watch-stdin flag has been added to only enable this
behaviour on request for the few applicable use cases.

A note has also been added in the Troubleshooting section to help any
final user that might start the dev-server as a background job.
@topaxi
Copy link
Contributor

topaxi commented Sep 1, 2018

Anything that needs to be done to get this merged / drive this forward? Let me know if I can help out.


When using create-react-app in a Phoenix application, the webpack-dev-server is not closed automatically if it's configured as a watcher. This is because Phoenix expects the watchers to close when the standart input is closed.

To watch for standart input you can pass the `--watch-stdin` option:
Copy link
Contributor

Choose a reason for hiding this comment

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

s/standart/standard/g ;)

@stale
Copy link

stale bot commented Nov 2, 2018

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs.

@stale stale bot added the stale label Nov 2, 2018
@stale
Copy link

stale bot commented Nov 7, 2018

This pull request has been automatically closed because it has not had any recent activity. The conversation will be locked in 7 days unless the pull request is reopened. Thank you for your contribution.

@stale stale bot closed this Nov 7, 2018
@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle stdin closing
5 participants