Skip to content

Commit ecd1552

Browse files
Improve error handling in stream response closure and ensure proper async barrier management
1 parent 9760cb9 commit ecd1552

File tree

1 file changed

+10
-3
lines changed
  • react_on_rails_pro/lib/react_on_rails_pro/concerns

1 file changed

+10
-3
lines changed

react_on_rails_pro/lib/react_on_rails_pro/concerns/stream.rb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ def stream_view_containing_react_components(template:, close_stream_at_end: true
5050

5151
begin
5252
drain_streams_concurrently(parent_task)
53-
ensure
53+
# Do not close the response stream in an ensure block.
54+
# If an error occurs we may need the stream open to send diagnostic/error details
55+
# (for example, ApplicationController#rescue_from in the dummy app).
5456
response.stream.close if close_stream_at_end
5557
end
5658
end
@@ -67,8 +69,13 @@ def drain_streams_concurrently(parent_task)
6769
end
6870

6971
# Wait for all component streaming tasks to complete
70-
@async_barrier.wait
71-
72+
begin
73+
@async_barrier.wait
74+
rescue StandardError => e
75+
@async_barrier.stop
76+
raise e
77+
end
78+
ensure
7279
# Close the queue to signal end of streaming
7380
@main_output_queue.close
7481
writing_task.wait

0 commit comments

Comments
 (0)