High CPU Usage and File Saving Issues with code-server on FUSE File System
Is there an existing issue for this?
- [X] I have searched the existing issues
OS/Web Information
- Web Browser: Chrome
- Local OS: macOS
- Remote OS: Ubuntu
- Remote Architecture: x64
code-server --version: 4.92.2
Steps to Reproduce
- Launch code-server and open a directory of a FUSE file system.
- Repeatedly modify and save a file within that FUSE file system.
Observed Behavior:
During the file modification process, I noticed that there was a period when files could not be saved properly. Additionally, the CPU usage for the processes located at /usr/lib/code-server/lib/node and /usr/lib/code-server/out/node/entry spiked to 100%.
The tab bar consistently indicates that the file is being written, but the server logs do not show any corresponding write file actions. Meanwhile, code-server is saving my edits to ~/.local/share/code-server/User/Backups.
Troubleshooting Attempts:
To further investigate the issue, I used the perf tool to analyze the call chain, but I was unable to pinpoint the exact cause. Below is the flame graph of the program's execution:
Suspected Causes:
I suspect that the program may be caught in an infinite loop, leading to high CPU usage and file-saving issues. Although I reviewed the Node.js source code, I could not identify any explicit causes for an infinite loop. It seems likely that this problem could be related to the 'fs' library utilized by code-server.
I would appreciate any insights or suggestions from the community regarding this issue, especially if anyone has faced a similar problem or has experience with FUSE file systems in conjunction with code-server. Thank you!
Expected
Files should be saved without issues, and the CPU usage by code-server should remain stable.
Actual
Saving fails, and the code-server process consumes excessive CPU resources.
Logs
No response
Screenshot/Video
No response
Does this bug reproduce in native VS Code?
I did not test native VS Code
Does this bug reproduce in GitHub Codespaces?
I did not test GitHub Codespaces
Are you accessing code-server over a secure context?
- [x] I am using a secure context.
Notes
I will provide all the information I know. Thank you!
To clarify, after I restarted the code-server process and killed the high CPU usage process, the file magically started saving normally again. I also noticed that only one file encounters the error at a time, while other files in the same directory can still be saved without any issues.
I unfortunately have no insight, but I did want to at least comment that since code-server just wraps VS Code, likely there will be more knowledge about what could cause this in the VS Code repository, or the Node.js one. But it would be nice if we can reproduce without code-server before sending upstream. One idea is to try code serve-web with Microsoft's build of VS Code, and see if it reproduces.
I think I have found the problem. It is due to the vscode file watcher mechanism. Vscode uses a third-party library called https://github.com/parcel-bundler/watcher which uses inotify to monitor file change events. However, the corresponding implementation of the fuse file system does not implement the inotify-related interface.
Using inotify-tools to track file changes revealed that, as shown in the above image, there were multiple ACCESS events followed by only one CLOSE event. This discrepancy led VSCode to wait for the lock release upon saving files, causing 100% CPU utilization and preventing the file from being saved during this period.
The finally solution is to add the corresponding folder in the configuration item "Files: Watcher Exclude".
Nice debugging!! I will go ahead and close this out as an upstream issue.