splitclient-rb 8.10.0.pre.rc5 → 8.10.0.pre.rc7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/splitclient-rb/sse/event_source/client.rb +53 -56
- data/lib/splitclient-rb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 996c61b1cd0a431ef21c5dff6eda92b553d96f81586470b89e7bbe49d2625923
|
|
4
|
+
data.tar.gz: 25643beb6250dd2e34e0e2d324ac4559ceeeb57a965ab7aeade1ce7cb73810ed
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 446a6dfd308323b5136b4f521e74e5d619cb49f2241f51ca446b8052997fc501485571f4ec45b1f12d17187bd308b4084d6b903a1c080da93cfc94a25f0caa74
|
|
7
|
+
data.tar.gz: 6b7b280649134be59a443c1a95838aa524ba4046a0948c2de2fc2faabcb288a66e0736dcd02196eddfdf3e0881e71d8a128ff86f1959b8b9a3b3bd621af3d5df
|
|
@@ -38,12 +38,15 @@ module SplitIoClient
|
|
|
38
38
|
|
|
39
39
|
def close(status = nil)
|
|
40
40
|
unless connected?
|
|
41
|
-
|
|
41
|
+
@config.logger.debug('SSEClient already disconected.')
|
|
42
42
|
return
|
|
43
43
|
end
|
|
44
|
+
@config.logger.debug("Closing SSEClient socket")
|
|
44
45
|
|
|
45
46
|
@connected.make_false
|
|
47
|
+
@socket.sync_close = true if @socket.is_a? OpenSSL::SSL::SSLSocket
|
|
46
48
|
@socket.close
|
|
49
|
+
@config.logger.debug("SSEClient socket state #{@socket.state}") if @socket.is_a? OpenSSL::SSL::SSLSocket
|
|
47
50
|
push_status(status)
|
|
48
51
|
rescue StandardError => e
|
|
49
52
|
@config.logger.error("SSEClient close Error: #{e.inspect}")
|
|
@@ -57,7 +60,6 @@ module SplitIoClient
|
|
|
57
60
|
|
|
58
61
|
@uri = URI(url)
|
|
59
62
|
latch = Concurrent::CountDownLatch.new(1)
|
|
60
|
-
|
|
61
63
|
connect_thread(latch)
|
|
62
64
|
|
|
63
65
|
return false unless latch.wait(CONNECT_TIMEOUT)
|
|
@@ -76,56 +78,65 @@ module SplitIoClient
|
|
|
76
78
|
|
|
77
79
|
def connect_thread(latch)
|
|
78
80
|
@config.threads[:connect_stream] = Thread.new do
|
|
79
|
-
|
|
81
|
+
@config.logger.info('Starting connect_stream thread ...')
|
|
80
82
|
new_status = connect_stream(latch)
|
|
81
83
|
push_status(new_status)
|
|
82
|
-
|
|
84
|
+
@config.logger.info('connect_stream thread finished.')
|
|
83
85
|
end
|
|
84
86
|
end
|
|
85
87
|
|
|
86
88
|
def connect_stream(latch)
|
|
87
89
|
return Constants::PUSH_NONRETRYABLE_ERROR unless socket_write(latch)
|
|
88
90
|
while connected? || @first_event.value
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
91
|
+
begin
|
|
92
|
+
if IO.select([@socket], nil, nil, @read_timeout)
|
|
93
|
+
begin
|
|
94
|
+
partial_data = @socket.readpartial(10_000)
|
|
95
|
+
read_first_event(partial_data, latch)
|
|
96
|
+
|
|
97
|
+
raise 'eof exception' if partial_data == :eof
|
|
98
|
+
rescue IO::WaitReadable => e
|
|
99
|
+
@config.logger.debug("SSE client IO::WaitReadable transient error: #{e.inspect}")
|
|
100
|
+
IO.select([@socket], nil, nil, @read_timeout)
|
|
101
|
+
retry
|
|
102
|
+
rescue Errno::EAGAIN => e
|
|
103
|
+
@config.logger.debug("SSE client transient error: #{e.inspect}")
|
|
104
|
+
IO.select([@socket], nil, nil, @read_timeout)
|
|
105
|
+
retry
|
|
106
|
+
rescue Errno::ETIMEDOUT => e
|
|
107
|
+
@config.logger.error("SSE read operation timed out!: #{e.inspect}")
|
|
108
|
+
return Constants::PUSH_RETRYABLE_ERROR
|
|
109
|
+
rescue EOFError => e
|
|
110
|
+
puts "SSE read operation EOF Exception!: #{e.inspect}"
|
|
111
|
+
@config.logger.error("SSE read operation EOF Exception!: #{e.inspect}")
|
|
112
|
+
raise 'eof exception'
|
|
113
|
+
rescue Errno::EBADF, IOError => e
|
|
114
|
+
@config.logger.error("SSE read operation EBADF or IOError: #{e.inspect}")
|
|
115
|
+
return Constants::PUSH_RETRYABLE_ERROR
|
|
116
|
+
rescue StandardError => e
|
|
117
|
+
@config.logger.error("SSE read operation StandardError: #{e.inspect}")
|
|
118
|
+
return nil if ENV['SPLITCLIENT_ENV'] == 'test'
|
|
119
|
+
|
|
120
|
+
@config.logger.error("Error reading partial data: #{e.inspect}")
|
|
121
|
+
return Constants::PUSH_RETRYABLE_ERROR
|
|
122
|
+
end
|
|
123
|
+
else
|
|
124
|
+
@config.logger.error("SSE read operation timed out, no data available.")
|
|
118
125
|
return Constants::PUSH_RETRYABLE_ERROR
|
|
119
126
|
end
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
127
|
+
rescue Errno::EBADF
|
|
128
|
+
@config.logger.debug("SSE socket is not connected (Errno::EBADF)")
|
|
129
|
+
break
|
|
130
|
+
rescue RuntimeError
|
|
131
|
+
raise 'eof exception'
|
|
132
|
+
rescue Exception => e
|
|
133
|
+
@config.logger.debug("SSE socket is not connected: #{e.inspect}")
|
|
134
|
+
break
|
|
124
135
|
end
|
|
125
136
|
|
|
126
137
|
process_data(partial_data)
|
|
127
138
|
end
|
|
128
|
-
|
|
139
|
+
@config.logger.info("SSE read operation exited: #{connected?}")
|
|
129
140
|
|
|
130
141
|
nil
|
|
131
142
|
end
|
|
@@ -136,7 +147,7 @@ module SplitIoClient
|
|
|
136
147
|
@socket.puts(build_request(@uri))
|
|
137
148
|
true
|
|
138
149
|
rescue StandardError => e
|
|
139
|
-
|
|
150
|
+
@config.logger.error("Error during connecting to #{@uri.host}. Error: #{e.inspect}")
|
|
140
151
|
latch.count_down
|
|
141
152
|
false
|
|
142
153
|
end
|
|
@@ -179,9 +190,8 @@ module SplitIoClient
|
|
|
179
190
|
IO.select(nil, [ssl_socket])
|
|
180
191
|
retry
|
|
181
192
|
end
|
|
182
|
-
|
|
183
193
|
return ssl_socket
|
|
184
|
-
|
|
194
|
+
|
|
185
195
|
rescue Exception => e
|
|
186
196
|
@config.logger.error("socket connect error: #{e.inspect}")
|
|
187
197
|
return nil
|
|
@@ -192,7 +202,7 @@ module SplitIoClient
|
|
|
192
202
|
end
|
|
193
203
|
|
|
194
204
|
def process_data(partial_data)
|
|
195
|
-
|
|
205
|
+
@config.logger.debug("Event partial data: #{partial_data}")
|
|
196
206
|
return if partial_data.nil? || partial_data == KEEP_ALIVE_RESPONSE
|
|
197
207
|
|
|
198
208
|
events = @event_parser.parse(partial_data)
|
|
@@ -210,7 +220,7 @@ module SplitIoClient
|
|
|
210
220
|
req << "SplitSDKMachineName: #{@config.machine_name}\r\n"
|
|
211
221
|
req << "SplitSDKClientKey: #{@api_key.split(//).last(4).join}\r\n" unless @api_key.nil?
|
|
212
222
|
req << "Cache-Control: no-cache\r\n\r\n"
|
|
213
|
-
|
|
223
|
+
@config.logger.debug("Request info: #{req}")
|
|
214
224
|
req
|
|
215
225
|
end
|
|
216
226
|
|
|
@@ -248,19 +258,6 @@ module SplitIoClient
|
|
|
248
258
|
@config.logger.debug("Pushing new sse status: #{status}")
|
|
249
259
|
@status_queue.push(status)
|
|
250
260
|
end
|
|
251
|
-
|
|
252
|
-
def log_if_debug(text, level)
|
|
253
|
-
if @config.debug_enabled
|
|
254
|
-
case level
|
|
255
|
-
when 1
|
|
256
|
-
@config.logger.debug(text)
|
|
257
|
-
when 2
|
|
258
|
-
@config.logger.info(text)
|
|
259
|
-
else
|
|
260
|
-
@config.logger.error(text)
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
end
|
|
264
261
|
end
|
|
265
262
|
end
|
|
266
263
|
end
|