Commit 90ea185
Fix ApiConnection authorization header thread safety (#9610)
* Fix ApiConnection authorization header thread safety
SetAuthenticator(HttpRequestMessage) was writing the Authorization
header to the shared HttpClient.DefaultRequestHeaders on every request.
HttpHeaders is not thread safe: under concurrent requests one thread
mutates the collection while another enumerates it during request
serialization, causing NullReferenceException failures, and requests
could also be serialized with a mismatched Authorization/Timestamp
pair causing intermittent authentication failures.
Set the Authorization header on the request message itself instead.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Include stack trace when logging unexpected api request exceptions
Network failures are already described by their HttpRequestError and
SocketErrorCode details and are frequent during outages, so they stay
on a single line. Any other exception type is unexpected, include its
stack trace so the source can be located directly from the logs.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
* Harden ApiConnection.TryRequestAsync request path
Guard against a null RequestUri, which is valid when the client has a
BaseAddress set, and handle response deserialization failures with the
http status code and raw response content instead of surfacing a parse
exception, for example an html error page returned by a proxy.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent c283231 commit 90ea185
1 file changed
Lines changed: 22 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
| 248 | + | |
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
| |||
323 | 334 | | |
324 | 335 | | |
325 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
326 | 343 | | |
327 | 344 | | |
328 | 345 | | |
| |||
360 | 377 | | |
361 | 378 | | |
362 | 379 | | |
363 | | - | |
364 | 380 | | |
365 | 381 | | |
366 | 382 | | |
367 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
368 | 386 | | |
369 | 387 | | |
370 | 388 | | |
| |||
0 commit comments