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

Fix(filewatcher): handle removed directories #8800 #9406

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

krlvi
Copy link
Contributor

@krlvi krlvi commented Nov 7, 2024

Description

When setting up manual recursive watching on folders (as is the case under Linux), the watching thread should not exit if a directory no longer exists. This is likely to occur within build output directories and it should not be the cause for interrupting the daemon.

Likely fixes #8800 and #8491

Testing Instructions

Unit tests suite

cargo test -p turborepo-filewatch

Test building of GitBulter

(Within a Fedora Linux VM)

  1. Prerequisites
sudo dnf check-update
sudo dnf install webkit2gtk4.1-devel \
  openssl-devel \
  curl \
  wget \
  file \
  libappindicator-gtk3-devel \
  librsvg2-devel
sudo dnf group install "C Development Tools and Libraries"
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
  1. Obtain test project sources
git clone https://github.com/gitbutlerapp/gitbutler
cd gitbutler
  1. Replace turbo with the turbo binary built from this branch, as an example:
diff --git a/package.json b/package.json
index 394d0f8e9..8f46a08e1 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
                "dev:ui": "pnpm --filter @gitbutler/ui storybook",
                "dev:web": "turbo watch --filter @gitbutler/web dev",
                "dev:desktop": "pnpm tauri dev",
-               "dev:internal-tauri": "turbo watch --filter @gitbutler/desktop dev",
+               "dev:internal-tauri": "/home/parallels/src/turborepo/target/debug/turbo watch --filter @gitbutler/desktop dev",
                "package": "turbo run package",
                "test": "turbo run test --no-daemon",
                "test:watch": "pnpm --filter @gitbutler/desktop run test:watch",
  1. Build project
pnpm install
pnpm tauri dev

@krlvi krlvi requested a review from a team as a code owner November 7, 2024 21:40
@turbo-orchestrator turbo-orchestrator bot added needs: triage New issues get this label. Remove it after triage owned-by: turborepo labels Nov 7, 2024
Copy link

vercel bot commented Nov 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 14, 2024 9:42pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-gatsby-web ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm
examples-vite-web ⬜️ Ignored (Inspect) Visit Preview Nov 14, 2024 9:42pm

Copy link

vercel bot commented Nov 7, 2024

@krlvi is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

When setting up manual recursive watching on folders (as is the case under Linux),
the watching thread should not exit if a directory no longer exists.
This is likely to occur within build output directories and it should
not be the cause for interrupting the daemon.
Bumps buffers size for package change events from 1024 to 4096.
With some build tools (e.g. cargo) the number of changes to the build
direcotry can be quite large resulting in processing delay.

It is also likely that during build operations the cpu resources are
constrained further contributing to delays in event processing,
thus increasing the buffer size seems appropriate
@krlvi
Copy link
Contributor Author

krlvi commented Nov 7, 2024

Hi @NicholasLYang - I noticed your comment here #8765 (comment) and also your name in git history and thought ping you on this PR for some feedback.

Background

Normally I build our project on Mac where we experience no issues, however recently had the need to build it in a Linux VM and noticed the turbo filewatcher misbehaving.
Subsequently, I noticed that other people were also struggling to build GitButler (a turbo project) on Linux (gitbutlerapp/gitbutler#5039). With some more searching I discovered this issue #8491 from another turbo project, as well as these two #8800 #8765

I did some manual testing with the projects mentioned but of course I wanted to reach out to see if there might be something I have not considered here.

@@ -604,7 +604,7 @@ impl proto::turbod_server::Turbod for TurboGrpcServiceInner {
.package_changes()
.await;

let (tx, rx) = mpsc::channel(1024);
let (tx, rx) = mpsc::channel(4096);
Copy link

Choose a reason for hiding this comment

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

I just wanted to surface the description for the commit-message as a motivation for this change, which should remove any element of surprise.

Bumps buffers size for package change events from 1024 to 4096.
With some build tools (e.g. cargo) the number of changes to the build
direcotry can be quite large resulting in processing delay.

It is also likely that during build operations the cpu resources are
constrained further contributing to delays in event processing,
thus increasing the buffer size seems appropriate

@ndom91
Copy link

ndom91 commented Nov 8, 2024

Can confirm, this seems to have allowed me to run turbo watch on my Nix box finally! 🥳

Copy link
Contributor

@NicholasLYang NicholasLYang left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Looks good to me, I'd just add a log line

break 'outer;
match err {
WatchError::WalkDir(_) => {
// Likely the path no longer exists
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a debug log here for this scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for taking a look! Added a dbg log statement here f9e08fc

Adds debug logging when setting up file watching fails due to
the directory no longer existing
@dBianchii
Copy link

Hi, I am one of those affected by the issue described here

How do I test this patch on my monorepo? Sorry to ask, as I don't know how to apply these changes to my exact repo.

@krlvi
Copy link
Contributor Author

krlvi commented Nov 11, 2024

Hi, I am one of those affected by the issue described here

How do I test this patch on my monorepo? Sorry to ask, as I don't know how to apply these changes to my exact repo.

Hey! If you have things set up you could build turborepo from source https://github.com/vercel/turborepo/blob/main/CONTRIBUTING.md using this branch and then in your on own project's build setup you can replace the references to turbo with the full path to the binary built from source.

Perhaps there is a way to create a binary with CI here, but as an external contributor I don't have permission to trigger CI

@ijjk
Copy link
Member

ijjk commented Nov 13, 2024

Allow CI Workflow Run

  • approve CI run for commit: f9e08fc

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@NicholasLYang
Copy link
Contributor

@dBianchii I'll try to get this merged ASAP so we can release a canary with it

@dBianchii
Copy link

@dBianchii I'll try to get this merged ASAP so we can release a canary with it

Thank you. It's breaking my setup all the time and I'm sure many others experience it on Linux.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: triage New issues get this label. Remove it after triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File watching fails due to file not found on Ubuntu 22.04 LTS
6 participants