Commit 2d9e06d
committed
fix(sqs): drain non-200 body, log close err, options struct
PR #721 round 1 review fixes:
1) Gemini medium — Body.Close error silently ignored
defer func() { _ = resp.Body.Close() }() dropped any close
error. A failed Close indicates a connection that the
http.Transport will tear down rather than reuse — under load
this can mask leaking connections / file descriptors. Logged
via slog.Warn with the peer address so operators can grep the
cluster log when triaging.
2) Claude minor — non-200 body not drained
resp.Body.Close() without first draining the body prevents the
http.Transport from reusing the underlying TCP connection. In a
control-plane path (one CreateQueue call per gate check) this
is acceptable, but if the gate ever fans out across many peers
under load, the failed-peer branch would force connection
teardown on every error response. Drain via
io.Copy(io.Discard, io.LimitReader(resp.Body,
sqsCapabilityMaxBodyBytes)) before the early return so the
transport can reuse the connection.
3) Claude nit — per-peer cap not exercised independently
TestPollSQSHTFIFOCapability_TimeoutFailsClosed used a 500ms
parent ctx — the request actually timed out via the parent
context, not the per-peer cap. The default 3s per-peer cap was
never independently exercised by tests.
Refactored signature to PollSQSHTFIFOCapability(ctx, peers,
cfg PollerConfig). PollerConfig{HTTPClient, PerPeerTimeout} is
the single options surface — zero values pick safe defaults.
Renamed the existing test to
TestPollSQSHTFIFOCapability_ParentContextDeadlineFailsClosed
and added
TestPollSQSHTFIFOCapability_PerPeerTimeoutFailsClosed which
uses context.Background() and PerPeerTimeout=100ms to exercise
the cap independently.
PerPeerTimeout is also a sensible operator knob — different
cluster latencies want different bounds. Caller-side: only
*_test.go files use the function today; PR 5's CreateQueue gate
will pick the appropriate timeout when it wires this up.
4) Claude minor — buildSQSHealthURL double-path edge case
A caller passing a URL that already includes the health path
(e.g. "http://node:5050/sqs_health") would receive a doubled
path. Added an explicit test case to TestBuildSQSHealthURL
documenting the behavior and the contract ("pass a base URL or
host:port, never a full request URL"). A future refactor can
intentionally change the contract; the test will catch it.
5) Audit per the lessons-learned discipline
PollSQSHTFIFOCapability is exported but has no production
callers yet — only the test file references it. grep confirmed
the API change is safe.1 parent 9e5ecd1 commit 2d9e06d
2 files changed
Lines changed: 121 additions & 35 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
73 | 96 | | |
74 | 97 | | |
75 | 98 | | |
| |||
90 | 113 | | |
91 | 114 | | |
92 | 115 | | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
97 | 122 | | |
98 | 123 | | |
99 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
100 | 129 | | |
101 | 130 | | |
102 | 131 | | |
| |||
119 | 148 | | |
120 | 149 | | |
121 | 150 | | |
122 | | - | |
| 151 | + | |
123 | 152 | | |
124 | 153 | | |
125 | 154 | | |
| |||
142 | 171 | | |
143 | 172 | | |
144 | 173 | | |
145 | | - | |
| 174 | + | |
146 | 175 | | |
147 | 176 | | |
148 | 177 | | |
149 | 178 | | |
150 | 179 | | |
151 | 180 | | |
152 | 181 | | |
153 | | - | |
| 182 | + | |
154 | 183 | | |
155 | 184 | | |
156 | 185 | | |
| |||
166 | 195 | | |
167 | 196 | | |
168 | 197 | | |
169 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
170 | 210 | | |
171 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
172 | 216 | | |
173 | 217 | | |
174 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
109 | | - | |
| 108 | + | |
| 109 | + | |
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
130 | 129 | | |
131 | 130 | | |
132 | | - | |
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
| |||
141 | 139 | | |
142 | 140 | | |
143 | 141 | | |
144 | | - | |
145 | | - | |
146 | | - | |
| 142 | + | |
147 | 143 | | |
148 | 144 | | |
149 | 145 | | |
150 | 146 | | |
151 | | - | |
| 147 | + | |
152 | 148 | | |
153 | 149 | | |
154 | 150 | | |
155 | 151 | | |
156 | | - | |
157 | | - | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
158 | 188 | | |
159 | 189 | | |
160 | 190 | | |
| |||
165 | 195 | | |
166 | 196 | | |
167 | 197 | | |
168 | | - | |
| 198 | + | |
169 | 199 | | |
170 | 200 | | |
171 | 201 | | |
| |||
176 | 206 | | |
177 | 207 | | |
178 | 208 | | |
179 | | - | |
| 209 | + | |
180 | 210 | | |
181 | 211 | | |
182 | 212 | | |
| |||
191 | 221 | | |
192 | 222 | | |
193 | 223 | | |
194 | | - | |
| 224 | + | |
195 | 225 | | |
196 | 226 | | |
197 | 227 | | |
| |||
225 | 255 | | |
226 | 256 | | |
227 | 257 | | |
228 | | - | |
| 258 | + | |
229 | 259 | | |
230 | 260 | | |
231 | 261 | | |
| |||
252 | 282 | | |
253 | 283 | | |
254 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
255 | 297 | | |
256 | 298 | | |
257 | 299 | | |
| |||
282 | 324 | | |
283 | 325 | | |
284 | 326 | | |
285 | | - | |
| 327 | + | |
286 | 328 | | |
287 | 329 | | |
288 | 330 | | |
| |||
0 commit comments