Commit da134d0
fix: resolve SignalR proxy memory leak by creating middleware once
Fixed MaxListenersExceededWarning errors (11+ listeners on Socket objects) that
occurred when refreshing the page with F5.
Root Cause:
- createProxyMiddleware was instantiated on every request to /api/signalr
- Each instance attached event listeners (error, close, unpipe, finish) to Socket objects
- Multiple concurrent requests during page refresh created multiple proxy instances
- Event listeners accumulated without cleanup, triggering Node.js memory leak warnings
Solution:
- Moved createProxyMiddleware instantiation to server startup (once)
- Created singleton signalrProxy instance
- Reused same instance for all requests and WebSocket upgrades
- Proxy middleware now properly manages its own listener lifecycle
Result:
- Event listeners remain constant (4 listeners per proxy instance)
- No more MaxListenersExceededWarning when refreshing
- Proper cleanup of connections handled by single middleware instance
Fixes: MaxListenersExceededWarning: Possible EventTarget memory leak detected
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 21acbb7 commit da134d0
1 file changed
+28
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 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 | + | |
14 | 40 | | |
15 | 41 | | |
16 | 42 | | |
| |||
22 | 48 | | |
23 | 49 | | |
24 | 50 | | |
25 | | - | |
| 51 | + | |
26 | 52 | | |
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 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | 70 | | |
83 | 71 | | |
84 | 72 | | |
| |||
0 commit comments