Commit 92c05a4
authored
fix(task): use shared memory for fspy ipc (#234)
Implemented a shared memory IPC channel for fspy to improve performance and reliability when tracking file system accesses.
The channel implementation is cross-platform. In this PR it's only adopted in macOS/Linux version of `fspy`. Windows version of `fspy` will switch to it in a separate PR.
### Why make this change?
The previous IPC implementation uses **file descriptor inheritance** to pass down the IPC channel. It has the risk of descriptors being closed in the child processes. Some defensive logic was implemented to handle it, including:
- Increase the fd number to avoid Node.js closing small fds: https://github.com/voidzero-dev/vite-plus/blob/540f597f50d049d444a09356da7c929b6da10b22/crates/fspy/src/unix/mod.rs#L156
- Intercept `posix_spawn` to avoid being closed by `POSIX_SPAWN_CLOEXEC_DEFAULT`: https://github.com/voidzero-dev/vite-plus/blob/540f597f50d049d444a09356da7c929b6da10b22/crates/fspy_preload_unix/src/client/mod.rs#L208
It apparently missed some cases, and the IPC fd still got closed, leading to `bad descriptor` error in https://github.com/voidzero-dev/vibe-dashboard/actions/runs/18532354385/job/52818262992.
### What changed?
- Created a new shared memory-based IPC channel implementation for fspy that replaces the previous Unix socket approach.
- The shared memory is looked up **based on names instead of descriptors**, making it impossible to be unexpectedly closed in child processes.
- Proper file locking is added to ensure safe access to shared memory
- Writing to the IPC channel **becomes much faster as it now only does some atomic memory operations** and doesn't trigger any syscalls.
- Modified the semantics of fs access tracking:
- The previous implementation automatically waits for the root target process and all its descendants to exit due to the nature of file descriptor inheritance.
- The new implementation requires waiting `accesses_future` after the root target process has exited. If descendants are spawned after the root target process has exited, their fs accesses will be missed.
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> Replaces Unix fspy IPC with a lock-backed shared-memory channel and updates payloads, readers, and callers; adds test utils and adjusts env/TLS dependencies.
>
> - **IPC (core)**:
> - Introduces shared-memory IPC (`fspy_shared::ipc::channel`) with `Sender`/`Receiver` and lock-guarded `ShmReader`/`ShmWriter` for zero-syscall writes.
> - **fspy (Unix/macOS)**:
> - Switches from FD/Unix-socket IPC to shared memory; payload now carries `ChannelConf` instead of an FD.
> - Refactors `SpyInner::init_in`, fixture handling, and path injection; reads frames via shared memory; lazy-locks receiver after child exit.
> - **Preload (Unix)**:
> - Client sends `PathAccess` via shared memory; removes POSIX spawn FD-inheritance handling; minor argv handling fix.
> - **Windows**:
> - Keeps pipe IPC; small fix to `NativeStr` construction and a temporary task to avoid blocking.
> - **API/Semantics & Callers**:
> - `accesses_future` must be awaited after child exit; updates examples, tests, e2e, and `vite_task` execution flow accordingly.
> - Adds `fspy_test_utils` crate for cross-process test helpers.
> - **Shared types**:
> - Enhances `NativeStr`/`NativeString` for zero-copy (ANSI/wide) and cross-platform encoding; updates spawn payload/env usage.
> - **Dependencies**:
> - Adds `shared_memory`, `memmap2`, `uuid`, `tracing`; tweaks `nix` features; switches `reqwest` to `native-tls-vendored` (adds `openssl-src`).
> - **Misc**:
> - Cleans up obsolete files and adjusts test steps (platform filters).
>
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 8f35015. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent e687c62 commit 92c05a4
31 files changed
Lines changed: 1284 additions & 456 deletions
File tree
- bench
- crates
- fspy_e2e/src
- fspy_preload_unix/src
- client
- interceptions/spawn
- fspy_preload_windows/src/windows/detours
- fspy_test_utils
- src
- fspy
- examples
- src
- unix
- windows
- tests
- vite_task/src
- fspy
- packages/cli/snap-tests/vitest-browser-mode
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| 76 | + | |
76 | 77 | | |
77 | 78 | | |
78 | 79 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
112 | 114 | | |
113 | 115 | | |
114 | 116 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | 44 | | |
47 | 45 | | |
48 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | | - | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
7 | 5 | | |
8 | 6 | | |
9 | 7 | | |
| |||
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | | - | |
21 | | - | |
22 | | - | |
| 18 | + | |
23 | 19 | | |
24 | 20 | | |
25 | 21 | | |
| |||
30 | 26 | | |
31 | 27 | | |
32 | 28 | | |
33 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
37 | 35 | | |
38 | | - | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | 42 | | |
51 | 43 | | |
52 | 44 | | |
| |||
0 commit comments