@@ -9,9 +9,7 @@ class Request # rubocop:disable Metrics/ClassLength
99 class << self
1010 def reset_connection
1111 @connection &.close
12- @connection_without_retries &.close
1312 @connection = create_connection
14- @connection_without_retries = create_connection ( enable_retries : false )
1513 end
1614
1715 def render_code ( path , js_code , send_bundle )
@@ -84,29 +82,17 @@ def asset_exists_on_vm_renderer?(filename)
8482
8583 private
8684
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-
9185 def connection
9286 @connection ||= create_connection
9387 end
9488
95- def connection_without_retries
96- @connection_without_retries ||= create_connection ( enable_retries : false )
97- end
98-
99- def perform_request ( path , **post_options ) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
100- # For streaming requests, use connection without retries to prevent body duplication
101- # The StreamRequest class handles retries properly by starting fresh requests
102- conn = post_options [ :stream ] ? connection_without_retries : connection
103-
89+ def perform_request ( path , **post_options ) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
10490 available_retries = ReactOnRailsPro . configuration . renderer_request_retry_limit
10591 retry_request = true
10692 while retry_request
10793 begin
10894 start_time = Time . now
109- response = conn . post ( path , **post_options )
95+ response = connection . post ( path , **post_options )
11096 raise response . error if response . is_a? ( HTTPX ::ErrorResponse )
11197
11298 request_time = Time . now - start_time
@@ -231,20 +217,17 @@ def common_form_data
231217 ReactOnRailsPro ::Utils . common_form_data
232218 end
233219
234- def create_connection ( enable_retries : true )
220+ def create_connection
235221 url = ReactOnRailsPro . configuration . renderer_url
236222 Rails . logger . info do
237223 "[ReactOnRailsPro] Setting up Node Renderer connection to #{ url } "
238224 end
239225
240- http_client = HTTPX
241- # For persistent connections we want retries,
242- # so the requests don't just fail if the other side closes the connection
243- # https://honeyryderchuck.gitlab.io/httpx/wiki/Persistent
244- # However, for streaming requests, retries cause body duplication
245- # See https://github.com/shakacode/react_on_rails/issues/1895
246- http_client = http_client . plugin ( :retries , max_retries : 1 , retry_change_requests : true ) if enable_retries
247- http_client
226+ HTTPX
227+ # For persistent connections we want retries,
228+ # so the requests don't just fail if the other side closes the connection
229+ # https://honeyryderchuck.gitlab.io/httpx/wiki/Persistent
230+ . plugin ( :retries , max_retries : 1 , retry_change_requests : true )
248231 . plugin ( :stream )
249232 # See https://www.rubydoc.info/gems/httpx/1.3.3/HTTPX%2FOptions:initialize for the available options
250233 . with (
0 commit comments