Skip to content

Commit b41d641

Browse files
committed
replace timeout block with IO call
1 parent d2da707 commit b41d641

2 files changed

Lines changed: 32 additions & 25 deletions

File tree

lib/splitclient-rb/sse/event_source/client.rb

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,39 @@ def connect_stream(latch)
8787
return Constants::PUSH_NONRETRYABLE_ERROR unless socket_write(latch)
8888
while connected? || @first_event.value
8989
log_if_debug("Inside coonnect_stream while loop.", 3)
90-
begin
91-
partial_data = ""
92-
Timeout::timeout @read_timeout do
90+
if IO.select([@socket], nil, nil, @read_timeout)
91+
begin
9392
partial_data = @socket.readpartial(10_000)
94-
end
95-
read_first_event(partial_data, latch)
96-
97-
raise 'eof exception' if partial_data == :eof
98-
rescue Timeout::Error => e
99-
log_if_debug("SSE read operation timed out!: #{e.inspect}", 3)
100-
return Constants::PUSH_RETRYABLE_ERROR
101-
rescue EOFError => e
102-
log_if_debug("SSE read operation EOF Exception!: #{e.inspect}", 3)
103-
raise 'eof exception'
104-
rescue Errno::EAGAIN => e
105-
log_if_debug("SSE client transient error: #{e.inspect}", 1)
106-
IO.select([tcp_socket])
107-
retry
108-
rescue Errno::EBADF, IOError => e
109-
log_if_debug("SSE read operation EBADF or IOError: #{e.inspect}", 3)
110-
return nil
111-
rescue StandardError => e
112-
log_if_debug("SSE read operation StandardError: #{e.inspect}", 3)
113-
return nil if ENV['SPLITCLIENT_ENV'] == 'test'
93+
read_first_event(partial_data, latch)
11494

115-
log_if_debug("Error reading partial data: #{e.inspect}", 3)
95+
raise 'eof exception' if partial_data == :eof
96+
rescue IO::WaitReadable => e
97+
log_if_debug("SSE client transient error: #{e.inspect}", 1)
98+
IO.select([@socket], nil, nil, @read_timeout)
99+
retry
100+
rescue Errno::ETIMEDOUT => e
101+
log_if_debug("SSE read operation timed out!: #{e.inspect}", 3)
102+
return Constants::PUSH_RETRYABLE_ERROR
103+
rescue EOFError => e
104+
log_if_debug("SSE read operation EOF Exception!: #{e.inspect}", 3)
105+
raise 'eof exception'
106+
rescue Errno::EAGAIN => e
107+
log_if_debug("SSE client transient error: #{e.inspect}", 1)
108+
IO.select([@socket], nil, nil, @read_timeout)
109+
retry
110+
rescue Errno::EBADF, IOError => e
111+
log_if_debug("SSE read operation EBADF or IOError: #{e.inspect}", 3)
112+
return nil
113+
rescue StandardError => e
114+
log_if_debug("SSE read operation StandardError: #{e.inspect}", 3)
115+
return nil if ENV['SPLITCLIENT_ENV'] == 'test'
116+
117+
log_if_debug("Error reading partial data: #{e.inspect}", 3)
118+
return Constants::PUSH_RETRYABLE_ERROR
119+
end
120+
else
121+
# Timeout occurred, no data available
122+
log_if_debug("SSE read operation timed out, no data available.", 3)
116123
return Constants::PUSH_RETRYABLE_ERROR
117124
end
118125

lib/splitclient-rb/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module SplitIoClient
2-
VERSION = '8.10.0-rc4'
2+
VERSION = '8.10.0-rc5'
33
end

0 commit comments

Comments
 (0)