fix watchers never being cleaned up #18559
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, there was an issue, where a slow compilation could cause the watchers to build up and never be cleaned. This would result in both excessive logging and the compilation time increasing exponentially.
This fix is a naive patch, simply locking if there is a build in progress, and unlocking when it completes. I'm marking it as a draft because I believe this lock can get stuck in a locked state resulting in the project never rebuilding.
The setup for this is a little involved, as it requires slowing down tailwind compilation enough so that the callback is triggered multiple times concurrently, but using the script below I was able to reproduce it fairly reliably:
Requirements
We need a way to stress the CPU to slow down tailwind compilation, for example stress-ng.
It can be install with apt, homebrew or similar.
Installation
There is a one-liner at the bottom to perform the required setup and run the tailwindcli.
Create a new directory:
Create a package.json with the correct deps.
Create the input css:
Install tailwind, daisyui, and some HTML to make tailwind do some work:
Usage
This is easiest with 3 terminal windows:
Start a tailwindcli watcher in one terminal:
Start a stress test in another:
Force repeated compilation in another:
Result
Once the stress test has completed, you can run:
You should see that there is repeated output, and the duration is in the multiple seconds.
If this setup doesn't cause the issue, you can also add the
-p
flag which causes theCSS to be printed, slowing things down further:
One-liner