Commit de3977d
Add client disconnect handling for concurrent component streaming (#2137)
## Summary
Adds error handling for client disconnects during streaming, which was
missing after the architecture change in #2111.
## Background
- **#2015** introduced concurrent component streaming with
`Async::Semaphore`
- **#2017** and **#2026** added client disconnect handling for that
architecture (both closed, not merged)
- **#2111** rewrote the streaming architecture using `Async::Barrier` +
`Async::Variable` + `Async::LimitedQueue`
- The error handling from #2017/#2026 was never adapted for the new
architecture
## Problem
When a client disconnects mid-stream (browser closed, network drop),
`response.stream.write` raises `IOError` or `Errno::EPIPE`. Without
handling:
1. The exception crashes the request
2. Producer tasks continue processing and enqueueing chunks
unnecessarily, wasting CPU
## Changes
### 1. Writer error handling (`stream.rb`)
- Catch `IOError`/`Errno::EPIPE` in writing task
- Set `client_disconnected` flag and stop barrier to cancel producer
tasks
- Log disconnect for debugging (when `logging_on_server` enabled)
### 2. Producer early termination (`react_on_rails_pro_helper.rb`)
- Add `stream.closed?` check before processing each chunk
- Prevents deadlock when producer blocks on full queue after writer dies
- Prevents wasted CPU when producer runs ahead of failed writer
- Extract `process_stream_chunks` method for clarity
### 3. Configuration validation (`configuration.rb`)
- Add setter validation for `concurrent_component_streaming_buffer_size`
- Must be a positive integer
### 4. Tests
- Add `client disconnect handling` describe block with IOError and EPIPE
tests
- Add buffer size validation tests
- Add `closed?` stub to stream test setup
## Test Plan
- [x] `bundle exec rspec spec/react_on_rails_pro/` - all 152 tests pass
- [x] `bundle exec rubocop` - no offenses
- [x] Verified tests fail on master, pass on this branch
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved streaming stability: better client-disconnect detection,
logging, and shutdown to avoid wasted work while preserving previous
chunk delivery semantics.
* **Configuration**
* Added a validated setting for concurrent streaming buffer size; only
positive integers are accepted.
* **Enhancements**
* Centralized stream chunk processing for more consistent handling of
first and subsequent chunks.
* **Tests**
* Added tests covering disconnect scenarios and buffer-size validation.
<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude <[email protected]>1 parent 16b3908 commit de3977d
File tree
6 files changed
+234
-32
lines changed- react_on_rails_pro
- app/helpers
- lib/react_on_rails_pro
- concerns
- spec
- dummy/spec/helpers
- react_on_rails_pro
6 files changed
+234
-32
lines changedLines changed: 24 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 316 | + | |
335 | 317 | | |
336 | 318 | | |
337 | 319 | | |
| |||
340 | 322 | | |
341 | 323 | | |
342 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
343 | 348 | | |
344 | 349 | | |
345 | 350 | | |
| |||
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
63 | 74 | | |
| 75 | + | |
| 76 | + | |
64 | 77 | | |
65 | 78 | | |
66 | 79 | | |
67 | 80 | | |
68 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
69 | 86 | | |
70 | 87 | | |
71 | 88 | | |
| |||
76 | 93 | | |
77 | 94 | | |
78 | 95 | | |
79 | | - | |
| 96 | + | |
80 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
81 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
82 | 114 | | |
83 | 115 | | |
84 | 116 | | |
Lines changed: 20 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
| |||
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
121 | | - | |
122 | 140 | | |
123 | 141 | | |
124 | 142 | | |
| |||
210 | 228 | | |
211 | 229 | | |
212 | 230 | | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | 231 | | |
222 | 232 | | |
223 | 233 | | |
| |||
Lines changed: 62 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
| |||
378 | 380 | | |
379 | 381 | | |
380 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
381 | 391 | | |
382 | 392 | | |
383 | 393 | | |
| |||
452 | 462 | | |
453 | 463 | | |
454 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
455 | 497 | | |
456 | 498 | | |
457 | 499 | | |
| |||
476 | 518 | | |
477 | 519 | | |
478 | 520 | | |
| 521 | + | |
479 | 522 | | |
480 | 523 | | |
481 | 524 | | |
| |||
565 | 608 | | |
566 | 609 | | |
567 | 610 | | |
| 611 | + | |
568 | 612 | | |
569 | 613 | | |
570 | 614 | | |
| |||
709 | 753 | | |
710 | 754 | | |
711 | 755 | | |
712 | | - | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
713 | 759 | | |
714 | 760 | | |
715 | 761 | | |
| |||
720 | 766 | | |
721 | 767 | | |
722 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
723 | 776 | | |
724 | 777 | | |
725 | 778 | | |
| |||
780 | 833 | | |
781 | 834 | | |
782 | 835 | | |
| 836 | + | |
783 | 837 | | |
784 | 838 | | |
785 | 839 | | |
| |||
790 | 844 | | |
791 | 845 | | |
792 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
793 | 853 | | |
794 | 854 | | |
795 | 855 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
260 | 260 | | |
261 | 261 | | |
262 | 262 | | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
263 | 300 | | |
264 | 301 | | |
0 commit comments