ndb 1.21.1 → 1.22.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 742d59480dc61a6b3a11bcc75e37036995f1c2e5a24f77e34f5b402a3989d970
4
- data.tar.gz: 259dccd7773250671b6872e384539f25df1ed2707c56454452f792af3124dd3f
3
+ metadata.gz: 7f8bbbaa584fd5c502ee0bf9da69dab20622c64c2ce5b9b2d61a8081d27a1e05
4
+ data.tar.gz: eff6ddb2921c66296e11e1e5b8fed8edfb07cba5b839a462329e28be254ea097
5
5
  SHA512:
6
- metadata.gz: 71227603e6200672b3bfc4d95aedbc9778f9ea7706cc8856d24139468df29b1732c334d8cdb0bf1634683099938040c6641d2bef41fafd03a9a948296e235713
7
- data.tar.gz: 59499efbb4198962233a432cb9c770b20f2623dc3ee14e1c8637097deba8635e87be4d278f5923a9bb196ed768645db73ade70dded4d47c4ea77261dfaeba36a
6
+ metadata.gz: c74e08b394626337a974fd036f90fe44ad65034a9c776438528b8a81583ad944ddd15de9499d07255833f421180f638953d3a18bfcb57af86cd5756540fa42a5
7
+ data.tar.gz: 11cee3ae7ed41a602149fe7ba36ae2625be24a43112a44ffdd3f180f216b3fd37080c9af1943c39975767bc212783408680b6c71ee91ddd686ab96584808d578
data/README.md CHANGED
@@ -59,7 +59,7 @@ Ndb::Client.new(
59
59
  - A bad address raises `ArgumentError` at once.
60
60
  - `ready_timeout` is how long a call retries while the daemon is not ready (`not_ready`, or the socket is missing or refuses). It uses exponential backoff (50 ms up to 1 s) with jitter. A write is retried only when the daemon certainly did not process it. A read is also retried after a dropped connection. A timeout is never retried. When the deadline passes, the last error is raised.
61
61
  - `health` does not wait: a daemon that is recovering raises `Ndb::NotReady`.
62
- - A reused keep-alive connection that the server closed is sent again only for a read. A write is never sent twice.
62
+ - Before it uses an idle keep-alive connection again, the client checks that the server did not close it (the idle timeout of the daemon is 60 s, and a proxy can have a shorter one). A closed one is replaced, so a write after a quiet time does not fail. A connection that drops during a request is sent again only for a read. A write is never sent twice.
63
63
  - The pool is thread-safe and drops its connections after a `fork`.
64
64
 
65
65
  ## Collections
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "io/wait"
3
4
  require "openssl"
4
5
  require "socket"
5
6
  require "uri"
@@ -110,6 +111,8 @@ module Ndb
110
111
  # stream read waits longer than the default). A read timeout
111
112
  # (IO::TimeoutError) raises Ndb::TimeoutError and is never sent again.
112
113
  def request(method, target, body, headers: {}, idempotent: false, timeout: nil)
114
+ close if closed_by_server?
115
+
113
116
  reused = !@socket.nil?
114
117
 
115
118
  begin
@@ -171,6 +174,17 @@ module Ndb
171
174
 
172
175
  private
173
176
 
177
+ # An idle keep-alive connection has nothing to read. When it is readable,
178
+ # the server closed it (the idle timeout of the daemon, a proxy): the
179
+ # next request opens a new one, so a write is never lost on it.
180
+ def closed_by_server?
181
+ return false unless @socket
182
+
183
+ @socket.to_io.wait_readable(0) ? true : false
184
+ rescue IOError, SystemCallError
185
+ true
186
+ end
187
+
174
188
  def open_socket
175
189
  @socket = @endpoint.connect(@timeout)
176
190
  @socket.timeout = @timeout if @socket.respond_to?(:timeout=)
data/lib/ndb/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ndb
4
- VERSION = "1.21.1"
4
+ VERSION = "1.22.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.21.1
4
+ version: 1.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thadeu