ldclient-rb 5.0.0 → 5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 743c38bedf7c153667c5a38fcc2deaffd557f09d
4
- data.tar.gz: c352ed4f8c412e2c19edcbe94d5813a2478ddade
3
+ metadata.gz: 9a11c0c98ebb0903ef634be9bab4779e88fac992
4
+ data.tar.gz: 6248ed0604ba3ef0c4c7a871d7803d4fec026c9a
5
5
  SHA512:
6
- metadata.gz: 6add89667ba084d57d7e49b52ced7ff279aa491aabc2285354353ce6b6f8393f14c04bef18062b1762ab6cf0bc97b27060009e589f78523fe8acaba9c9ff4a3d
7
- data.tar.gz: 0a46454ca002c7fc35d15fc2343097727552cdc81ef517d96032befe77a451ddbd9e3f99b048cec5e132480c4ebb124685a8cdd282c6982f1c40844ceef7313b
6
+ metadata.gz: 0dd10cb337613fb44efb0492090ecedc08bdae9c279ce05af2578cdcbd199b20c7b2d314e7d6e31ce8b09c092e74ffb9187b011d5a76672c20a6ad760db445b7
7
+ data.tar.gz: 4105be290c1951b38d569cea473422ad5178a7ddab511e9df7accf2e1ef7d9ee60d6d3774063278f2cb45ae3aba831dc95aba62503d4acb21ac4af0f182a6620
@@ -2,6 +2,11 @@
2
2
 
3
3
  All notable changes to the LaunchDarkly Ruby SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## [5.0.1] - 2018-07-02
6
+ ### Fixed:
7
+ Fixed a regression in version 5.0.0 that could prevent the client from reconnecting if the stream connection was dropped by the server.
8
+
9
+
5
10
  ## [5.0.0] - 2018-06-26
6
11
  ### Changed:
7
12
  - The client no longer uses Celluloid for streaming I/O. Instead, it uses [socketry](https://github.com/socketry/socketry).
@@ -1,3 +1,3 @@
1
1
  module LaunchDarkly
2
- VERSION = "5.0.0"
2
+ VERSION = "5.0.1"
3
3
  end
@@ -61,6 +61,7 @@ module SSE
61
61
  def close
62
62
  if @stopped.make_true
63
63
  @cxn.close if !@cxn.nil?
64
+ @cxn = nil
64
65
  end
65
66
  end
66
67
 
@@ -77,6 +78,9 @@ module SSE
77
78
  @cxn = nil
78
79
  begin
79
80
  @cxn = connect
81
+ # There's a potential race if close was called in the middle of the previous line, i.e. after we
82
+ # connected but before @cxn was set. Checking the variable again is a bit clunky but avoids that.
83
+ return if @stopped.value
80
84
  read_stream(@cxn) if !@cxn.nil?
81
85
  rescue Errno::EBADF
82
86
  # don't log this - it probably means we closed our own connection deliberately
@@ -84,7 +88,12 @@ module SSE
84
88
  @logger.error { "Unexpected error from event source: #{e.inspect}" }
85
89
  @logger.debug { "Exception trace: #{e.backtrace}" }
86
90
  end
87
- @cxn.close if !cxn.nil?
91
+ begin
92
+ @cxn.close if !@cxn.nil?
93
+ rescue StandardError => e
94
+ @logger.error { "Unexpected error while closing stream: #{e.inspect}" }
95
+ @logger.debug { "Exception trace: #{e.backtrace}" }
96
+ end
88
97
  end
89
98
  end
90
99
 
@@ -1,3 +1,4 @@
1
+ require "concurrent/atomics"
1
2
  require "http_tools"
2
3
  require "socketry"
3
4
 
@@ -15,11 +16,14 @@ module SSE
15
16
  @reader = HTTPResponseReader.new(@socket, read_timeout)
16
17
  @status = @reader.status
17
18
  @headers = @reader.headers
19
+ @closed = Concurrent::AtomicBoolean.new(false)
18
20
  end
19
21
 
20
22
  def close
21
- @socket.close if @socket
22
- @socket = nil
23
+ if @closed.make_true
24
+ @socket.close if @socket
25
+ @socket = nil
26
+ end
23
27
  end
24
28
 
25
29
  # Generator that returns one line of the response body at a time (delimited by \r, \n,
@@ -136,4 +136,42 @@ EOT
136
136
  end
137
137
  end
138
138
  end
139
+
140
+ it "reconnects if stream returns EOF" do
141
+ events_body_1 = <<-EOT
142
+ event: go
143
+ data: foo
144
+
145
+ EOT
146
+ events_body_2 = <<-EOT
147
+ event: go
148
+ data: bar
149
+
150
+ EOT
151
+ with_server do |server|
152
+ attempt = 0
153
+ server.setup_response("/") do |req,res|
154
+ attempt += 1
155
+ if attempt == 1
156
+ res.body = events_body_1
157
+ else
158
+ res.body = events_body_2
159
+ end
160
+ res.content_type = "text/event-stream"
161
+ res.status = 200
162
+ end
163
+
164
+ event_sink = Queue.new
165
+ client = subject.new(server.base_uri,
166
+ reconnect_time: 0.25, read_timeout: 0.25) do |c|
167
+ c.on_event { |event| event_sink << event }
168
+ end
169
+
170
+ with_client(client) do |client|
171
+ expect(event_sink.pop).to eq(SSE::SSEEvent.new(:go, "foo", nil))
172
+ expect(event_sink.pop).to eq(SSE::SSEEvent.new(:go, "bar", nil))
173
+ expect(attempt).to be >= 2
174
+ end
175
+ end
176
+ end
139
177
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ldclient-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.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: 2018-06-26 00:00:00.000000000 Z
11
+ date: 2018-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler