Commit b57639c
authored
Fix/server cpu exhaustion (#353)
* Fix server CPU exhaustion under high stream load
- Enforce maxSessions limit: reject new TCP connections when at capacity
instead of accepting and logging a debug message
- Add per-session concurrent stream limit (2048) using a semaphore to
prevent a single session (e.g. setup-node) from spawning unbounded
goroutines that starve the CPU
- Add backoff delay (50ms) on non-fatal stream accept errors to prevent
tight CPU spin loops when persistent errors occur
- Streams that exceed the concurrency limit are immediately closed
rather than queued, providing backpressure to the client
* Revert maxSessions rejection to original behavior
maxSessions only controls discovery advertisement, not connection
acceptance. Services and visors connect to all servers regardless
of advertised load, so rejecting sessions would break connectivity.
* Add stream read deadline and fix indentation
- Add read deadline (HandshakeTimeout) on initial stream request read
so slow or malicious clients cannot hold goroutines and semaphore
slots indefinitely. Deadline is cleared before the long-lived
bidirectional copy loop.
- Remove stale TODO comment in server accept loop
- Fix indentation from previous revert
* Ensure pprof HTTP server remains responsive under high load
Run the pprof HTTP server on a dedicated OS thread via
runtime.LockOSThread() and bump GOMAXPROCS by 1 to reserve a thread
for it. This ensures the kernel scheduler gives pprof CPU time even
when the Go runtime is saturated with thousands of stream-handling
goroutines, which is exactly when pprof is needed most to diagnose
the problem.1 parent 3016c2e commit b57639c
3 files changed
Lines changed: 98 additions & 42 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 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 | | - | |
| 24 | + | |
48 | 25 | | |
49 | 26 | | |
50 | 27 | | |
| |||
122 | 99 | | |
123 | 100 | | |
124 | 101 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 102 | + | |
140 | 103 | | |
141 | 104 | | |
142 | 105 | | |
| |||
149 | 112 | | |
150 | 113 | | |
151 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
18 | 29 | | |
19 | 30 | | |
20 | 31 | | |
| |||
45 | 56 | | |
46 | 57 | | |
47 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
48 | 63 | | |
49 | 64 | | |
50 | 65 | | |
| |||
54 | 69 | | |
55 | 70 | | |
56 | 71 | | |
| 72 | + | |
57 | 73 | | |
58 | 74 | | |
59 | 75 | | |
60 | 76 | | |
61 | | - | |
62 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
63 | 88 | | |
| 89 | + | |
64 | 90 | | |
65 | 91 | | |
66 | 92 | | |
| |||
79 | 105 | | |
80 | 106 | | |
81 | 107 | | |
| 108 | + | |
82 | 109 | | |
83 | 110 | | |
84 | 111 | | |
85 | 112 | | |
86 | | - | |
87 | 113 | | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
88 | 124 | | |
| 125 | + | |
89 | 126 | | |
90 | 127 | | |
91 | 128 | | |
| |||
101 | 138 | | |
102 | 139 | | |
103 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
104 | 149 | | |
105 | 150 | | |
106 | 151 | | |
| |||
183 | 228 | | |
184 | 229 | | |
185 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
186 | 236 | | |
187 | 237 | | |
188 | 238 | | |
| |||
0 commit comments