dalli 3.2.5 → 3.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc1fc3d1639a4e5380a972472d830cd6999f016672af936701201521433180e3
4
- data.tar.gz: 154207a695751bf6430f597783a6382bcb764f42e6f71303b2ead07f90e90f24
3
+ metadata.gz: c7d8b3dd9e76a224d876f901dc44c3cf8016326209df3efc7fe522053a4a3c22
4
+ data.tar.gz: 0ced058a6a170cadd4b74268de5417c4a1e700baf5767fc8f260db9477e2b735
5
5
  SHA512:
6
- metadata.gz: 4f7c65a4528f180ff8ccad3d39f0197cd83d409830e188e59fc8a03075e7a61c71c111db409cbefa01fb26d6e408fae2e5f2701e4f370744bf33a08023c33831
7
- data.tar.gz: cbd13ba3453f17eb012632f5d077552eb6ea46adbb349f4fb72b612c8d9fe2bb6a9b64641a2d105592d0def88ad7b467a1f007ed6abb76e8c0fdb8d94064c369
6
+ metadata.gz: 3e316a4d60c3327cecec46a0a34c52536130199124035c375bf1933676d85fbf09e99a985ae44faf4e27b0fb1f8b8faef1656a812e6bdfc387406c5e18874461
7
+ data.tar.gz: bce3e0e41c280e99889bea6835c1b2f701cbcb5e4f398203ae2b4d6ebc05cdc505ee5955365715f8e00441d69701ceac84de37a98eac8581d003d1ab411a33e9
data/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@ Dalli Changelog
4
4
  Unreleased
5
5
  ==========
6
6
 
7
+ 3.2.8
8
+ ==========
9
+
10
+ - Handle IO::TimeoutError when establishing connection (eugeneius)
11
+ - Drop dependency on base64 gem (Earlopain)
12
+ - Address incompatibility with resolv-replace (y9v)
13
+ - Add rubygems.org metadata (m-nakamura145)
14
+
15
+ 3.2.7
16
+ ==========
17
+
18
+ - Fix cascading error when there's an underlying network error in a pipelined get (eugeneius)
19
+ - Ruby 3.4/head compatibility by adding base64 to gemspec (tagliala)
20
+ - Add Ruby 3.3 to CI (m-nakamura145)
21
+ - Use Socket's connect_timeout when available, and pass timeout to the socket's send and receive timeouts (mlarraz)
22
+
23
+ 3.2.6
24
+ ==========
25
+
26
+ - Rescue IO::TimeoutError raised by Ruby since 3.2.0 on blocking reads/writes (skaes)
27
+ - Fix rubydoc link (JuanitoFatas)
7
28
 
8
29
  3.2.5
9
30
  ==========
data/README.md CHANGED
@@ -23,7 +23,7 @@ The name is a variant of Salvador Dali for his famous painting [The Persistence
23
23
  * [Announcements](https://github.com/petergoldstein/dalli/discussions/categories/announcements) - Announcements of interest to the Dalli community will be posted here.
24
24
  * [Bug Reports](https://github.com/petergoldstein/dalli/issues) - If you discover a problem with Dalli, please submit a bug report in the tracker.
25
25
  * [Forum](https://github.com/petergoldstein/dalli/discussions/categories/q-a) - If you have questions about Dalli, please post them here.
26
- * [Client API](https://rubydoc.info/github/petergoldstein/dalli/Dalli/Client) - Ruby documentation for the `Dalli::Client` API
26
+ * [Client API](https://www.rubydoc.info/gems/dalli) - Ruby documentation for the `Dalli::Client` API
27
27
 
28
28
  ## Development
29
29
 
@@ -60,7 +60,7 @@ module Dalli
60
60
  deleted = []
61
61
 
62
62
  servers.each do |server|
63
- next unless server.alive?
63
+ next unless server.connected?
64
64
 
65
65
  begin
66
66
  finish_query_for_server(server)
@@ -106,7 +106,7 @@ module Dalli
106
106
  end
107
107
 
108
108
  values
109
- rescue SystemCallError, Timeout::Error, EOFError => e
109
+ rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e
110
110
  @connection_manager.error_on_request!(e)
111
111
  end
112
112
 
@@ -52,7 +52,7 @@ module Dalli
52
52
  bitflags = extra_len.positive? ? body.unpack1('N') : 0x0
53
53
  key = body.byteslice(extra_len, key_len).force_encoding(Encoding::UTF_8) if key_len.positive?
54
54
  value = body.byteslice((extra_len + key_len)..-1)
55
- value = parse_as_stored_value ? @value_marshaller.retrieve(value, bitflags) : value
55
+ value = @value_marshaller.retrieve(value, bitflags) if parse_as_stored_value
56
56
  [key, value]
57
57
  end
58
58
 
@@ -55,7 +55,7 @@ module Dalli
55
55
  @sock = memcached_socket
56
56
  @pid = PIDCache.pid
57
57
  @request_in_progress = false
58
- rescue SystemCallError, Timeout::Error, EOFError, SocketError => e
58
+ rescue SystemCallError, *TIMEOUT_ERRORS, EOFError, SocketError => e
59
59
  # SocketError = DNS resolution failure
60
60
  error_on_request!(e)
61
61
  end
@@ -150,19 +150,19 @@ module Dalli
150
150
  data = @sock.gets("\r\n")
151
151
  error_on_request!('EOF in read_line') if data.nil?
152
152
  data
153
- rescue SystemCallError, Timeout::Error, EOFError => e
153
+ rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e
154
154
  error_on_request!(e)
155
155
  end
156
156
 
157
157
  def read(count)
158
158
  @sock.readfull(count)
159
- rescue SystemCallError, Timeout::Error, EOFError => e
159
+ rescue SystemCallError, *TIMEOUT_ERRORS, EOFError => e
160
160
  error_on_request!(e)
161
161
  end
162
162
 
163
163
  def write(bytes)
164
164
  @sock.write(bytes)
165
- rescue SystemCallError, Timeout::Error => e
165
+ rescue SystemCallError, *TIMEOUT_ERRORS => e
166
166
  error_on_request!(e)
167
167
  end
168
168
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'base64'
4
-
5
3
  module Dalli
6
4
  module Protocol
7
5
  class Meta
@@ -17,13 +15,15 @@ module Dalli
17
15
  def self.encode(key)
18
16
  return [key, false] if key.ascii_only? && !WHITESPACE.match(key)
19
17
 
20
- [Base64.strict_encode64(key), true]
18
+ strict_base64_encoded = [key].pack('m0')
19
+ [strict_base64_encoded, true]
21
20
  end
22
21
 
23
22
  def self.decode(encoded_key, base64_encoded)
24
23
  return encoded_key unless base64_encoded
25
24
 
26
- Base64.strict_decode64(encoded_key).force_encoding(Encoding::UTF_8)
25
+ strict_base64_decoded = encoded_key.unpack1('m0')
26
+ strict_base64_decoded.force_encoding(Encoding::UTF_8)
27
27
  end
28
28
  end
29
29
  end
@@ -1,8 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'timeout'
4
+
3
5
  module Dalli
4
6
  module Protocol
5
7
  # Preserved for backwards compatibility. Should be removed in 4.0
6
8
  NOT_FOUND = ::Dalli::NOT_FOUND
9
+
10
+ # Ruby 3.2 raises IO::TimeoutError on blocking reads/writes, but
11
+ # it is not defined in earlier Ruby versions.
12
+ TIMEOUT_ERRORS =
13
+ if defined?(IO::TimeoutError)
14
+ [Timeout::Error, IO::TimeoutError]
15
+ else
16
+ [Timeout::Error]
17
+ end
7
18
  end
8
19
  end
data/lib/dalli/socket.rb CHANGED
@@ -89,8 +89,7 @@ module Dalli
89
89
  attr_accessor :options
90
90
 
91
91
  def self.open(host, port, options = {})
92
- Timeout.timeout(options[:socket_timeout]) do
93
- sock = new(host, port)
92
+ create_socket_with_timeout(host, port, options) do |sock|
94
93
  sock.options = { host: host, port: port }.merge(options)
95
94
  init_socket_options(sock, options)
96
95
 
@@ -98,11 +97,39 @@ module Dalli
98
97
  end
99
98
  end
100
99
 
100
+ def self.create_socket_with_timeout(host, port, options)
101
+ # Check that TCPSocket#initialize was not overwritten by resolv-replace gem
102
+ # (part of ruby standard library since 3.0.0, should be removed in 3.4.0),
103
+ # as it does not handle keyword arguments correctly.
104
+ # To check this we are using the fact that resolv-replace
105
+ # aliases TCPSocket#initialize method to #original_resolv_initialize.
106
+ # https://github.com/ruby/resolv-replace/blob/v0.1.1/lib/resolv-replace.rb#L21
107
+ if RUBY_VERSION >= '3.0' &&
108
+ !::TCPSocket.private_instance_methods.include?(:original_resolv_initialize)
109
+ sock = new(host, port, connect_timeout: options[:socket_timeout])
110
+ yield(sock)
111
+ else
112
+ Timeout.timeout(options[:socket_timeout]) do
113
+ sock = new(host, port)
114
+ yield(sock)
115
+ end
116
+ end
117
+ end
118
+
101
119
  def self.init_socket_options(sock, options)
102
120
  sock.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, true)
103
121
  sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, true) if options[:keepalive]
104
122
  sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_RCVBUF, options[:rcvbuf]) if options[:rcvbuf]
105
123
  sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_SNDBUF, options[:sndbuf]) if options[:sndbuf]
124
+
125
+ return unless options[:socket_timeout]
126
+
127
+ seconds, fractional = options[:socket_timeout].divmod(1)
128
+ microseconds = fractional * 1_000_000
129
+ timeval = [seconds, microseconds].pack('l_2')
130
+
131
+ sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_RCVTIMEO, timeval)
132
+ sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_SNDTIMEO, timeval)
106
133
  end
107
134
 
108
135
  def self.wrapping_ssl_socket(tcp_socket, host, ssl_context)
data/lib/dalli/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dalli
4
- VERSION = '3.2.5'
4
+ VERSION = '3.2.8'
5
5
 
6
6
  MIN_SUPPORTED_MEMCACHED_VERSION = '1.4'
7
7
  end
data/lib/dalli.rb CHANGED
@@ -34,7 +34,7 @@ module Dalli
34
34
  QUIET = :dalli_multi
35
35
 
36
36
  def self.logger
37
- @logger ||= (rails_logger || default_logger)
37
+ @logger ||= rails_logger || default_logger
38
38
  end
39
39
 
40
40
  def self.rails_logger
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.5
4
+ version: 3.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter M. Goldstein
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-06-13 00:00:00.000000000 Z
12
+ date: 2024-02-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: High performance memcached client for Ruby
15
15
  email:
@@ -59,6 +59,8 @@ homepage: https://github.com/petergoldstein/dalli
59
59
  licenses:
60
60
  - MIT
61
61
  metadata:
62
+ bug_tracker_uri: https://github.com/petergoldstein/dalli/issues
63
+ changelog_uri: https://github.com/petergoldstein/dalli/blob/main/CHANGELOG.md
62
64
  rubygems_mfa_required: 'true'
63
65
  post_install_message:
64
66
  rdoc_options: []
@@ -75,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
77
  - !ruby/object:Gem::Version
76
78
  version: '0'
77
79
  requirements: []
78
- rubygems_version: 3.4.14
80
+ rubygems_version: 3.5.6
79
81
  signing_key:
80
82
  specification_version: 4
81
83
  summary: High performance memcached client for Ruby