ld-eventsource 2.6.0 → 3.0.0
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 -13
- data/lib/ld-eventsource/errors.rb +10 -0
- data/lib/ld-eventsource/version.rb +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dcf2b9358b588b57f4bba285ed1a91bd399fe04c74622a0d944fd3fa0c56e9bb
|
|
4
|
+
data.tar.gz: 22514811554b69e1225aebebb18bb531b65daf27c8f0d2284717791f21aeb771
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b20450c7187809e03706778149944c6268782c0b307b58874f569af2c6eb635ec125c65ed2d1c3077438f63a95e1dc86411743deb432f7da71aa4945bbfc12c1
|
|
7
|
+
data.tar.gz: 06dc4097880991e04e3ad8a8c3c3f0d01488849d84f0cc98444cbb8cb558b7a9949fc56169e3b18e569b2fe18b1900cd25404bf882f114c9816f0a715b1f9480
|
|
@@ -123,7 +123,7 @@ module SSE
|
|
|
123
123
|
retry_enabled: true,
|
|
124
124
|
http_client_options: nil)
|
|
125
125
|
@uri = URI(uri)
|
|
126
|
-
@
|
|
126
|
+
@stop_event = Concurrent::Event.new
|
|
127
127
|
@retry_enabled = retry_enabled
|
|
128
128
|
|
|
129
129
|
@headers = headers.clone
|
|
@@ -278,7 +278,7 @@ module SSE
|
|
|
278
278
|
# has no effect if called a second time.
|
|
279
279
|
#
|
|
280
280
|
def close
|
|
281
|
-
if @
|
|
281
|
+
if @stop_event.try?
|
|
282
282
|
reset_http
|
|
283
283
|
end
|
|
284
284
|
end
|
|
@@ -289,7 +289,7 @@ module SSE
|
|
|
289
289
|
# @return [Boolean] true if the client has been shut down
|
|
290
290
|
#
|
|
291
291
|
def closed?
|
|
292
|
-
@
|
|
292
|
+
@stop_event.set?
|
|
293
293
|
end
|
|
294
294
|
|
|
295
295
|
private
|
|
@@ -314,7 +314,7 @@ module SSE
|
|
|
314
314
|
end
|
|
315
315
|
|
|
316
316
|
def run_stream
|
|
317
|
-
until @
|
|
317
|
+
until @stop_event.set?
|
|
318
318
|
close_connection
|
|
319
319
|
begin
|
|
320
320
|
resp = connect
|
|
@@ -323,12 +323,16 @@ module SSE
|
|
|
323
323
|
end
|
|
324
324
|
# There's a potential race if close was called in the middle of the previous line, i.e. after we
|
|
325
325
|
# connected but before @cxn was set. Checking the variable again is a bit clunky but avoids that.
|
|
326
|
-
|
|
326
|
+
if @stop_event.set?
|
|
327
|
+
# close did not see this connection, so close it here.
|
|
328
|
+
reset_http
|
|
329
|
+
return
|
|
330
|
+
end
|
|
327
331
|
read_stream(resp) unless resp.nil?
|
|
328
332
|
rescue => e
|
|
329
333
|
# When we deliberately close the connection, it will usually trigger an exception. The exact type
|
|
330
|
-
# of exception depends on the specific Ruby runtime. But
|
|
331
|
-
if @
|
|
334
|
+
# of exception depends on the specific Ruby runtime. But the client will always be closed in this case.
|
|
335
|
+
if @stop_event.set?
|
|
332
336
|
@logger.info { "Stream connection closed" }
|
|
333
337
|
else
|
|
334
338
|
log_and_dispatch_error(e, "Unexpected error from event source")
|
|
@@ -347,12 +351,14 @@ module SSE
|
|
|
347
351
|
# Try to establish a streaming connection. Returns the StreamingHTTPConnection object if successful.
|
|
348
352
|
def connect
|
|
349
353
|
loop do
|
|
350
|
-
return if @
|
|
354
|
+
return if @stop_event.set?
|
|
351
355
|
interval = @first_attempt ? 0 : @backoff.next_interval
|
|
352
356
|
@first_attempt = false
|
|
353
357
|
if interval > 0
|
|
354
358
|
@logger.info { "Will retry connection after #{'%.3f' % interval} seconds" }
|
|
355
|
-
|
|
359
|
+
# This wait ends early when close sets the event.
|
|
360
|
+
@stop_event.wait(interval)
|
|
361
|
+
return if @stop_event.set?
|
|
356
362
|
end
|
|
357
363
|
cxn = nil
|
|
358
364
|
begin
|
|
@@ -395,7 +401,7 @@ module SSE
|
|
|
395
401
|
|
|
396
402
|
chunks = Enumerator.new do |gen|
|
|
397
403
|
loop do
|
|
398
|
-
if @
|
|
404
|
+
if @stop_event.set?
|
|
399
405
|
break
|
|
400
406
|
else
|
|
401
407
|
begin
|
|
@@ -407,9 +413,9 @@ module SSE
|
|
|
407
413
|
# For historical reasons, we rethrow this as our own type
|
|
408
414
|
raise Errors::ReadTimeoutError.new(@read_timeout)
|
|
409
415
|
rescue EOFError
|
|
410
|
-
|
|
416
|
+
raise Errors::StreamClosedByServerError
|
|
411
417
|
end
|
|
412
|
-
|
|
418
|
+
raise Errors::StreamClosedByServerError if data.nil? # keep for v5 compat
|
|
413
419
|
gen.yield data
|
|
414
420
|
end
|
|
415
421
|
end
|
|
@@ -417,7 +423,7 @@ module SSE
|
|
|
417
423
|
event_parser = Impl::EventParser.new(Impl::BufferedLineReader.lines_from(chunks), @last_id)
|
|
418
424
|
|
|
419
425
|
event_parser.items.each do |item|
|
|
420
|
-
return if @
|
|
426
|
+
return if @stop_event.set?
|
|
421
427
|
case item
|
|
422
428
|
when StreamEvent
|
|
423
429
|
dispatch_event(item)
|
|
@@ -79,5 +79,15 @@ module SSE
|
|
|
79
79
|
super("no data received in #{interval} seconds")
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
|
+
|
|
83
|
+
#
|
|
84
|
+
# An exception class indicating that the server ended the stream without an error. This is
|
|
85
|
+
# passed to the error handler specified in {Client#on_error}, and the client then reconnects.
|
|
86
|
+
#
|
|
87
|
+
class StreamClosedByServerError < StandardError
|
|
88
|
+
def initialize
|
|
89
|
+
super("stream closed by server")
|
|
90
|
+
end
|
|
91
|
+
end
|
|
82
92
|
end
|
|
83
93
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ld-eventsource
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
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-09-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: logger
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '1.5'
|
|
20
|
-
type: :development
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '1.5'
|
|
27
13
|
- !ruby/object:Gem::Dependency
|
|
28
14
|
name: rspec
|
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -128,6 +114,20 @@ dependencies:
|
|
|
128
114
|
- - "<"
|
|
129
115
|
- !ruby/object:Gem::Version
|
|
130
116
|
version: 7.0.0
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: logger
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - "~>"
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '1.5'
|
|
124
|
+
type: :runtime
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - "~>"
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '1.5'
|
|
131
131
|
description: LaunchDarkly SSE client for Ruby
|
|
132
132
|
email:
|
|
133
133
|
- team@launchdarkly.com
|