Commit 324805b
Fix body duplication in streaming requests on retry (#1895)
## Problem
When streaming SSR responses encountered connection errors mid-transmission
(e.g., "descriptor closed"), the HTTPx retries plugin would retry the request.
However, since partial HTML chunks were already sent to the client, the retry
would append the full response again, resulting in duplicated/corrupted HTML
and hydration failures.
## Root Cause
The HTTPx retries plugin (configured with max_retries: 1 in create_connection)
was automatically retrying failed streaming requests. Unlike regular requests,
streaming responses can be partially transmitted before failing, so retrying
causes body duplication:
- Original request: sends chunks 1, 2, 3, then fails
- Retry: sends chunks 1, 2, 3, 4, 5 (all chunks)
- Client receives: 1, 2, 3, 1, 2, 3, 4, 5 (duplicated!)
## Solution
- Disable HTTPx retries plugin specifically for streaming requests
- Create separate connection_without_retries for streaming
- StreamRequest class already handles retries properly by starting fresh
- Non-streaming requests continue to use retries for connection reliability
## Changes
- Add connection_without_retries method that creates connection without retries
- Update perform_request to use connection_without_retries for streaming
- Update reset_connection to close both connection types
- Add test to verify streaming requests don't use HTTPx retries
- Add comments explaining the fix and referencing the issue
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 5f195a7 commit 324805b
File tree
2 files changed
+51
-8
lines changed- react_on_rails_pro
- lib/react_on_rails_pro
- spec/react_on_rails_pro
2 files changed
+51
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
89 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
90 | 100 | | |
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
94 | 104 | | |
95 | | - | |
| 105 | + | |
96 | 106 | | |
97 | 107 | | |
98 | 108 | | |
| |||
217 | 227 | | |
218 | 228 | | |
219 | 229 | | |
220 | | - | |
| 230 | + | |
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
224 | 234 | | |
225 | 235 | | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
231 | 244 | | |
232 | 245 | | |
233 | 246 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
197 | 227 | | |
198 | 228 | | |
0 commit comments