-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Dangling tailwind-cli process when using Phoenix Framework #9264
Comments
Does Phoenix have the ability to control launched processes? I would expect it to close any child processes before it exits. You are absolutely right that the fix is the reverse of the one in esbuild but there was a reason for this. The general idea about mentioning it was that it checks if it's a tty or not. Not that it listens for stdin close when it is not a TTY. If you launch a process generally you do NOT have a TTY. But, in these situations, you also generally have direct control over the process so it can be exited by the program that launched it by sending the appropriate signal (a The problem here that were solving is:
This leads to the code we have for our fix. At least in the esbuild case it would also fail running in turborepo if it didn't explicitly close processes — which I believe it does otherwise they'd have the same problem (dangling processes). I would expect that existing the Pheonix server would kill any processes it launched before closing as well. Unfortunately, at least in Node.js, there does not appear to be a distinction between "I didn't connect stdin" and "I connected it but then it was closed". It's just immediately closed if it has no data. I'm also unsure if this distinction exists at all generally. I'm not sure what the best way to fix this is because, afaik, the only possible fix for this will break anything that doesn't use stdin. |
Based on this comment by Jose Valim, I presume it doesn't.
I know you will want to strive for maximal compatibility with everything, but maybe that is a bit of a problem? As far as I understand using stdin is the de-facto conventional solution to this problem. Using signal, while not uncommon, is fraught with problems like:
So perhaps my naive view point here is that turborepo should switch to using stdin. |
Although, as noted in that thread:
Which could be an issue for some runtimes? I am not sure what's the best fix here is either, other than introducing a flag at the expense of increased cli noise. |
I did a bit of poking around about how tools handle stdin closing. It seems like several of them do sometimes but how to enable this behavior differs considerably:
So even with standard unix/linux tools support for this is very inconsistent and has certain conditions making figuring this out much less clear cut. The one consistent thing is that it seems all the shells exit when stdin closes. The unfortunate side is that there is no correct answer here and all these tools have slightly different behavior ranging from never to only when {condition} to only when not {condition} to always. Basically every possible option. :/ I do think we need to change this so this is what I see as some possible paths forward:
I'll also note that I verified that esbuild's watcher does not work with Turborepo and that there is an open issue with them about forwarding stdin: vercel/turborepo#1235 I'll discuss this internally a bit more to see if we can come to a consensus on what we want to do here. |
So @reinink and I spent some time today on this and we found two things:
As such we've reverted the change and are suggesting people use Thanks for helping us through this one! ✨ |
What version of Tailwind CSS are you using?
For example: v3.1.8
What build tool (or framework if it abstracts the build tool) are you using?
Phoenix v1.6.11 (latest) with its tailwind plugin v0.1.8.
What version of Node.js are you using?
N/A. The phoenix tailwind plugin uses the tailwind-cli binary from this repo directly.
What operating system are you using?
Linux
Describe your issue
I believe this issue was originally fixed by Jose Valim's PR which added a listener on stdin. If stdin was closed, it was deemed that the parent process must have died, so tailwind process should clean itself up.
However following a reported issue in turborepo, @thecrypticace added a fix that only watches stdin closing when on TTY, citing esbuild's solution as inspiration. However, the esbuild solution was to listen to stdin closing when NOT on TTY because that's how frameworks like Phoenix spawns background processes like esbuild or tailwind, which sounds sensible to me. In any case, I believe this fix has now caused a regression in Phoenix.
While I think esbuild's solution of stdin listening when not on TTY is the correct approach and will fix this issue for Phoenix (though I haven't tested it), unfortunately I don't know what that will mean for turborepo.
The text was updated successfully, but these errors were encountered: