Commit 11afb64
committed
fix(web): dispose idle MCP server instances to prevent process accumulation
In `opencode web` mode, switching projects creates new Instance entries (each
spawning MCP server child processes) that are never cleaned up. Unlike the TUI
which calls shutdown()/disposeAll() on exit, the web command blocks forever
with `await new Promise(() => {})` and never reaches its `server.stop()` call.
This causes unbounded process growth — each project switch leaks ~200MB of MCP
server processes (linear, notion, etc.) that persist for the lifetime of the
web server.
Fix:
- Add signal handlers (SIGINT, SIGTERM, SIGHUP) to the web command that call
Instance.disposeAll() with a 5s timeout before exiting
- Add idle eviction to Instance: track last access time per directory, sweep
every 60s, and dispose instances idle for >5 minutes
- Clean up lastAccess bookkeeping in dispose() and disposeAll()1 parent 8c739b4 commit 11afb64
2 files changed
+74
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
78 | 94 | | |
79 | | - | |
80 | 95 | | |
81 | 96 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
16 | 65 | | |
17 | 66 | | |
18 | 67 | | |
19 | 68 | | |
20 | 69 | | |
21 | 70 | | |
22 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
23 | 75 | | |
24 | 76 | | |
25 | 77 | | |
| |||
70 | 122 | | |
71 | 123 | | |
72 | 124 | | |
| 125 | + | |
73 | 126 | | |
74 | 127 | | |
75 | 128 | | |
| |||
85 | 138 | | |
86 | 139 | | |
87 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
88 | 145 | | |
89 | 146 | | |
90 | 147 | | |
| |||
105 | 162 | | |
106 | 163 | | |
107 | 164 | | |
| 165 | + | |
108 | 166 | | |
109 | 167 | | |
110 | 168 | | |
| |||
0 commit comments