Commit 5a9563a
committed
fix(webapp): eliminate SSE abort-signal memory leak
AbortSignal.any() combined with abort(reason) on Node 20 pinned the full
Express request/response graph via a DOMException stack trace and a
FinalizationRegistry. Every aborted SSE connection leaked ~60KB
(ServerResponse, IncomingMessage, Socket, 4x AbortController, SpanImpl)
that survived GC indefinitely.
- sse.ts: collapse the 4-signal stack to a single internalController.signal;
replace AbortSignal.timeout() with a plain setTimeout cleared on abort;
drop every string arg from .abort() so no DOMException stack is captured;
removeEventListener the request-abort handler on cleanup.
- entry.server.tsx: clear the setTimeout(abort, ABORT_DELAY) in every
terminal callback so the abort closure does not pin the React render
tree + remixContext for 30s per successful request (react-router #14200).
- tracer.server.ts: gate HttpInstrumentation and ExpressInstrumentation
behind DISABLE_HTTP_INSTRUMENTATION=true for isolation testing; defaults
to enabled.
Verified locally (500 aborted SSE connections + GC):
- unpatched: +16.0 MB heap, 158 memlab leak clusters
- patched: +3.3 MB heap, 0 app-code leaks1 parent 2d3b2e8 commit 5a9563a
4 files changed
Lines changed: 52 additions & 41 deletions
File tree
- .server-changes
- apps/webapp/app
- utils
- v3
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
86 | 90 | | |
87 | 91 | | |
88 | 92 | | |
| |||
105 | 109 | | |
106 | 110 | | |
107 | 111 | | |
| 112 | + | |
108 | 113 | | |
109 | 114 | | |
| 115 | + | |
110 | 116 | | |
111 | 117 | | |
112 | 118 | | |
| |||
121 | 127 | | |
122 | 128 | | |
123 | 129 | | |
124 | | - | |
| 130 | + | |
125 | 131 | | |
126 | 132 | | |
127 | 133 | | |
| |||
135 | 141 | | |
136 | 142 | | |
137 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
138 | 148 | | |
139 | 149 | | |
140 | 150 | | |
| |||
157 | 167 | | |
158 | 168 | | |
159 | 169 | | |
| 170 | + | |
160 | 171 | | |
161 | 172 | | |
| 173 | + | |
162 | 174 | | |
163 | 175 | | |
164 | 176 | | |
| |||
173 | 185 | | |
174 | 186 | | |
175 | 187 | | |
176 | | - | |
| 188 | + | |
177 | 189 | | |
178 | 190 | | |
179 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
49 | 48 | | |
50 | 49 | | |
51 | 50 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
63 | | - | |
64 | 62 | | |
65 | 63 | | |
66 | 64 | | |
67 | | - | |
68 | 65 | | |
69 | 66 | | |
70 | 67 | | |
71 | 68 | | |
72 | | - | |
| 69 | + | |
73 | 70 | | |
74 | 71 | | |
75 | 72 | | |
| |||
92 | 89 | | |
93 | 90 | | |
94 | 91 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | 92 | | |
102 | 93 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
119 | 108 | | |
120 | | - | |
| 109 | + | |
121 | 110 | | |
122 | 111 | | |
123 | | - | |
124 | | - | |
125 | | - | |
| 112 | + | |
| 113 | + | |
126 | 114 | | |
127 | | - | |
| 115 | + | |
128 | 116 | | |
129 | 117 | | |
130 | 118 | | |
131 | 119 | | |
132 | 120 | | |
133 | 121 | | |
134 | | - | |
| 122 | + | |
135 | 123 | | |
136 | 124 | | |
137 | 125 | | |
138 | 126 | | |
139 | | - | |
| 127 | + | |
140 | 128 | | |
141 | 129 | | |
142 | 130 | | |
| |||
147 | 135 | | |
148 | 136 | | |
149 | 137 | | |
150 | | - | |
| 138 | + | |
151 | 139 | | |
152 | 140 | | |
153 | 141 | | |
154 | 142 | | |
155 | 143 | | |
156 | 144 | | |
157 | | - | |
| 145 | + | |
158 | 146 | | |
159 | 147 | | |
160 | 148 | | |
| |||
165 | 153 | | |
166 | 154 | | |
167 | 155 | | |
168 | | - | |
| 156 | + | |
169 | 157 | | |
170 | 158 | | |
171 | 159 | | |
172 | 160 | | |
173 | 161 | | |
174 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
175 | 166 | | |
176 | 167 | | |
177 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
306 | | - | |
307 | 305 | | |
308 | 306 | | |
309 | 307 | | |
310 | 308 | | |
311 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
312 | 314 | | |
313 | 315 | | |
314 | 316 | | |
| |||
0 commit comments