ld-eventsource 3.0.0 → 3.0.1
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/ld-eventsource/client.rb +19 -10
- data/lib/ld-eventsource/impl/backoff.rb +6 -6
- data/lib/ld-eventsource/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b9f8e00c1bed855a376158eb3a77bb6b72192d6bb432a231df00be8c5576712
|
|
4
|
+
data.tar.gz: 697c406733e7590e591632493d3ff30a2f239ad3600382cf862063e2c8cf39ae
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c9a9d34b776c35cdd2f54bad3abbc53b658669996878267f375e5e36e4160f6aafad06e1275b67ce9667d81e71917f5c6b01e5daf214f9b29f8ad4f96b73c6c
|
|
7
|
+
data.tar.gz: 4561ccd51021a0eeb33a82528e45738d8cda462060a05a9fa17df010485d32e98817740c12611164ff7ebeb4935a12027ce11be13d98ced17864e73828e779a9
|
|
@@ -315,7 +315,8 @@ module SSE
|
|
|
315
315
|
|
|
316
316
|
def run_stream
|
|
317
317
|
until @stop_event.set?
|
|
318
|
-
close_connection
|
|
318
|
+
log_close_errors { close_connection }
|
|
319
|
+
error = nil
|
|
319
320
|
begin
|
|
320
321
|
resp = connect
|
|
321
322
|
@lock.synchronize do
|
|
@@ -330,25 +331,25 @@ module SSE
|
|
|
330
331
|
end
|
|
331
332
|
read_stream(resp) unless resp.nil?
|
|
332
333
|
rescue => e
|
|
334
|
+
error = e
|
|
335
|
+
end
|
|
336
|
+
# Close the connection before the error handler runs, because the handler can block for a long time.
|
|
337
|
+
log_close_errors { reset_http }
|
|
338
|
+
unless error.nil?
|
|
333
339
|
# When we deliberately close the connection, it will usually trigger an exception. The exact type
|
|
334
340
|
# of exception depends on the specific Ruby runtime. But the client will always be closed in this case.
|
|
335
341
|
if @stop_event.set?
|
|
336
342
|
@logger.info { "Stream connection closed" }
|
|
337
343
|
else
|
|
338
|
-
log_and_dispatch_error(
|
|
344
|
+
log_and_dispatch_error(error, "Unexpected error from event source")
|
|
339
345
|
end
|
|
340
346
|
end
|
|
341
|
-
begin
|
|
342
|
-
reset_http
|
|
343
|
-
rescue StandardError => e
|
|
344
|
-
log_and_dispatch_error(e, "Unexpected error while closing stream")
|
|
345
|
-
end
|
|
346
347
|
|
|
347
348
|
return close unless @retry_enabled
|
|
348
349
|
end
|
|
349
350
|
end
|
|
350
351
|
|
|
351
|
-
# Try to establish a streaming connection. Returns the
|
|
352
|
+
# Try to establish a streaming connection. Returns the HTTP::Response object if successful.
|
|
352
353
|
def connect
|
|
353
354
|
loop do
|
|
354
355
|
return if @stop_event.set?
|
|
@@ -392,8 +393,7 @@ module SSE
|
|
|
392
393
|
end
|
|
393
394
|
end
|
|
394
395
|
|
|
395
|
-
# Pipe the output of the
|
|
396
|
-
# they arrive.
|
|
396
|
+
# Pipe the output of the HTTP::Response into the EventParser, and dispatch events as they arrive.
|
|
397
397
|
def read_stream(cxn)
|
|
398
398
|
# Tell the Backoff object that the connection is now in a valid state. It uses that information so
|
|
399
399
|
# it can automatically reset itself if enough time passes between failures.
|
|
@@ -453,6 +453,15 @@ module SSE
|
|
|
453
453
|
end
|
|
454
454
|
end
|
|
455
455
|
|
|
456
|
+
# A failure to close is logged but not dispatched, so each connection attempt gives the error
|
|
457
|
+
# handler at most one error, and the worker thread continues.
|
|
458
|
+
def log_close_errors
|
|
459
|
+
yield
|
|
460
|
+
rescue StandardError => e
|
|
461
|
+
@logger.warn { "Unexpected error while closing stream: #{e.inspect}" }
|
|
462
|
+
@logger.debug { "Exception trace: #{e.backtrace}" }
|
|
463
|
+
end
|
|
464
|
+
|
|
456
465
|
def build_headers
|
|
457
466
|
h = {
|
|
458
467
|
'Accept' => 'text/event-stream',
|
|
@@ -39,13 +39,13 @@ module SSE
|
|
|
39
39
|
@attempts = 0 if good_duration >= @reconnect_reset_interval
|
|
40
40
|
end
|
|
41
41
|
@last_good_time = nil
|
|
42
|
+
# A zero base must not be multiplied: 0.0 * Infinity is NaN. Also, rand(0) is not permitted.
|
|
43
|
+
return 0 if @base_interval <= 0 || @max_interval <= 0
|
|
44
|
+
|
|
42
45
|
target = [@base_interval * (2 ** @attempts), @max_interval].min.to_f
|
|
43
|
-
|
|
44
|
-
if target
|
|
45
|
-
|
|
46
|
-
else
|
|
47
|
-
(target / 2) + @jitter_rand.rand(target / 2)
|
|
48
|
-
end
|
|
46
|
+
# Stop at the ceiling, so that the power of 2 cannot grow without limit.
|
|
47
|
+
@attempts += 1 if target < @max_interval
|
|
48
|
+
(target / 2) + @jitter_rand.rand(target / 2)
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
#
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ld-eventsource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.
|
|
4
|
+
version: 3.0.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LaunchDarkly
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-10-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|