Skip to content

Commit bae4005

Browse files
justin808claude
andcommitted
Add documentation for memory tradeoff and retry handling
Addresses code review feedback: 1. Memory Management: Document that we maintain two separate HTTP connection pools (with and without retries), which doubles the memory footprint. This tradeoff is acceptable to prevent body duplication in streaming responses. 2. Retry Logic: Add comment in stream_request.rb explaining that retry logic for streaming requests is handled by starting fresh requests, and the HTTPx connection has retries disabled to prevent body duplication. These comments improve code maintainability by explaining the architectural decisions and their tradeoffs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 64c9dec commit bae4005

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

react_on_rails_pro/lib/react_on_rails_pro/request.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ def asset_exists_on_vm_renderer?(filename)
8484

8585
private
8686

87+
# NOTE: We maintain two separate HTTP connection pools to handle streaming vs non-streaming requests.
88+
# This doubles the memory footprint (e.g., if renderer_http_pool_size is 10, we use 20 total connections).
89+
# This tradeoff is acceptable to prevent body duplication in streaming responses.
90+
8791
def connection
8892
@connection ||= create_connection
8993
end

react_on_rails_pro/lib/react_on_rails_pro/stream_request.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def each_chunk(&block)
7575

7676
send_bundle = false
7777
error_body = +""
78+
# Retry logic for streaming requests is handled here by starting fresh requests.
79+
# The HTTPx connection used for streaming has retries disabled (see Request#connection_without_retries)
80+
# to prevent body duplication when partial chunks are already sent to the client.
7881
loop do
7982
stream_response = @request_executor.call(send_bundle)
8083

0 commit comments

Comments
 (0)