Commit 73ae220
fix(retry): handle UnexpectedEof and connection closed errors as retryable
Detect two additional connection-closed-by-peer scenarios in the retry
logic that were previously not treated as retryable:
1. TLS (rustls): peer closes connection without sending a TLS close_notify
alert, surfaced as std::io::Error(UnexpectedEof) in the source chain.
2. Plain HTTP / hyper: peer closes the TCP connection before sending a
complete HTTP response, surfaced as hyper's IncompleteMessage error
with the message 'connection closed before message completed'.
Both cases are safe to retry because the request was never acknowledged
by the server. This fixes the error observed against the ChatGPT codex
endpoint:
POST https://chatgpt.com/backend-api/codex/responses
peer closed connection without sending TLS close_notify
Adds has_unexpected_eof() helper that walks the reqwest::Error source
chain to detect either condition, and two async tests that simulate a
peer closing the TCP connection to verify the detection and retry path.
Co-Authored-By: ForgeCode <noreply@forgecode.dev>1 parent 6987017 commit 73ae220
2 files changed
Lines changed: 47 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
99 | 124 | | |
100 | 125 | | |
101 | 126 | | |
| |||
293 | 318 | | |
294 | 319 | | |
295 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
296 | 341 | | |
0 commit comments