-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
6.0.0-beta.7 regression, browser does not open with "spawn EBADF" error #18527
Comments
Does it work if you set |
I just tested and yes, Tested six attempts, three with and three without. |
chokidar v4 stopped using the Does it work if you increase the file descriptor limit? I'm thinking whether |
Yeah it does seem like a node issue. I wonder if using node 22 helps a bit. To workaround this, perhaps we can also do a retry for the exec if it fails with this error, but it looks like it could affect other code that calls exec too. |
Increasing ulimit
Unless I'm doing it wrong, this didn't seem to help. Default ulimit:
I did override it like this, and the issue persisted:
-- Node v22
Just switched to v22 with nvm, it didn't seem to make a difference. -- Retrying
At a first glance, this doesn't seem to be possible. The current crash is already a crashing spawn that's a fallback to a crashing exec. It appears like any call to exec or spawn anywhere would be affected. I've also just tested an async spawn, 10s after the first crash, and it does crash again.
-- Number of fs.watch callsTo provide extra information, I wrapped the At the moment the crash is happening, we have around 16723! And as I navigate around in the app, the number slowly increases to 17268. But seems relatively stable. It does not increase further when reaching twice for the same modules from the dev server. On the surface, all files being watched seem appropriate. Only 20-30 files at the root of the repo could be skipped, otherwise watched files are all typescript files that are part of the app. Nothing in node_modules is being watched. -- |
Thanks for the very thorough checks here. The consistent crash with spawn looks quite concerning to me. I think fsevents in chokidar v3 worked better on macos before as it watches by directories rather than files. It looks like If all doesn't work and we don't have a reasonable workaround, I'm not sure what alternatives we'd have besides downgrading chokidar for now. |
One interesting observation about this; That I see, fs.watch is called with the root directories of the app first, then it is called for every files in them thereafter. Maybe this is deliberate for some sophisticated reason, but that seemed odd. |
Some extra food for thought; Since this issue only happens on dep re-optimization and is more likely to happen with certain optimizeDeps configs, I suspect that in our case it happens a result of chokidar and tinyglobby competing for file descriptors. In other words, the chokidar update may be the one that pushed us over the edge for the first time, but the scalability issue may be kinda holistically larger in nature. It is also hard to know how many Vite users would be impacted for that reason. |
Hmm, would it work if you run
It seems it's implemented in Node 20.13+, 22.1+ (paulmillr/chokidar#1304 (comment)).
IIUC, the fs.watch for directories is needed to detect a new file created in that directory and the fs.watch for each files is needed to detect the file change. |
Ah you're right. I was reading the node 18 docs. Even with
I tested locally and watching the directory also seem to detect its file changes. Could be specific to the machine though |
Ah, it worked for me on Windows as well. Maybe it's worth exploring. |
Just tested and no luck. The bug remains reproducible. |
I wonder if |
I think |
Describe the bug
Starting with Vite 6.0.0-beta.7, the browser intermittently no longer opens when running "vite".
The console includes the following error:
--
Conditions
This bug is intermittent and making a small reproducible case is difficult:
optimizeDeps.include
is used in the config--
Details about the crash
The crash is a synchronous crash on
exec
andspawn
calls such as this one:https://github.com/vitejs/vite/blob/main/packages/vite/src/node/server/openBrowser.ts#L144
What is peculiar is that the callback of "exec" is never called. The exec call is throwing.
Result:
--
The regression commit
I ran a git bisect on the Vite repo and identified the following commit as the source for the regression:
feat!: update to chokidar v4
Because the bug is intermittent, the above finding is not guaranteed to be reliable, although I did re-run enough time to have a relatively high level of confidence in the finding.
--
I am very sorry for not providing a reproducible case. I was not able to create one but felt the above was likely still precise enough to be valuable information (particularly the git bisect).
This bug seems to be a scalability issue that is more likely to happen in large codebases where a lot of dependencies need to go through optimizeDeps.
The way node.js internal utils are crashing also seems indicative of a larger issue (e.g. is chokidar used in a manner that saturates node.js somehow?) which could potentially manifest in other ways and cause additional bugs elsewhere...
Reproduction
Steps to reproduce
Intermittent, to increase the chances of reproducing:
To reproduce:
System Info
Used Package Manager
yarn
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: