Skip to content

Commit 763a9ff

Browse files
justin808claude
andcommitted
Add debug logging for client disconnects and improve error handling
Improvements: - Add debug logging when client disconnects during streaming (producer/consumer) - Remove unnecessary explicit nil return in rescue block - Add test support for closed? method on mocked stream - Only logs when logging_on_server is enabled These changes improve observability for production debugging without affecting normal operation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e4a552e commit 763a9ff

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

react_on_rails_pro/lib/react_on_rails_pro/concerns/stream.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ def build_producer_tasks(parent:, queue:)
103103
# Will be blocked if the queue is full until a chunk is dequeued
104104
queue.enqueue([idx, chunk])
105105
end
106-
rescue IOError, Errno::EPIPE
106+
rescue IOError, Errno::EPIPE => e
107107
# Client disconnected - stop producing
108+
log_client_disconnect("producer", e)
108109
break
109110
end
110111
end
@@ -119,9 +120,17 @@ def build_writer_task(parent:, queue:)
119120
_idx_from_queue, item = pair
120121
response.stream.write(item)
121122
end
122-
rescue IOError, Errno::EPIPE
123+
rescue IOError, Errno::EPIPE => e
123124
# Client disconnected - stop writing
124-
nil
125+
log_client_disconnect("consumer", e)
126+
end
127+
end
128+
129+
def log_client_disconnect(context, exception)
130+
return unless ReactOnRails.configuration.logging_on_server
131+
132+
ReactOnRails.configuration.logger.debug do
133+
"[React on Rails Pro] Client disconnected during streaming (#{context}): #{exception.class}"
125134
end
126135
end
127136
end

react_on_rails_pro/spec/react_on_rails_pro/stream_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ def setup_stream_test(component_count: 2)
388388
allow(mocked_response).to receive(:stream).and_return(mocked_stream)
389389
allow(mocked_stream).to receive(:write)
390390
allow(mocked_stream).to receive(:close)
391+
allow(mocked_stream).to receive(:closed?).and_return(false)
391392
allow(controller).to receive(:response).and_return(mocked_response)
392393

393394
[component_queues, controller, mocked_stream]

0 commit comments

Comments
 (0)