dalli 5.2.7 → 5.2.8
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/CHANGELOG.md +8 -0
- data/lib/dalli/compressor.rb +52 -15
- data/lib/dalli/protocol/base.rb +22 -7
- data/lib/dalli/protocol/connection_manager.rb +9 -0
- data/lib/dalli/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: 4fa868aa2b92a8669cc00416effa319b3122ebb39140b4621eb25185b0fc114f
|
|
4
|
+
data.tar.gz: 45cd331ebc4366007ec0fd49d172fb7042b49680bc49ca947f8b43fd9d3b2367
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a69bc353299d1d8dea6a877cdec90149ab750083fcad768f0246b20ed0cd1f07c119df48bbb0e842ddbe01d32be9419e4a218d58e41d40d30c4b81a187e400e5
|
|
7
|
+
data.tar.gz: 1cf619274e1e90679a85698b6114c2a24fef8064b94694a0c2b522d6495c1611265851f5530a7063a0f0602866d42a4b7bec120f9e4a29fd575922f9612dd7f4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
Dalli Changelog
|
|
2
2
|
=====================
|
|
3
3
|
|
|
4
|
+
5.2.8
|
|
5
|
+
==========
|
|
6
|
+
|
|
7
|
+
Bug fixes:
|
|
8
|
+
|
|
9
|
+
- `set_multi` and `delete_multi` on more than one server retried forever, hanging the caller, when a server accepted their writes and then closed the connection before replying. Each quiet write reset the server's failure count, so it never reached `socket_max_failures`. Only a request whose reply is read resets it now, and the server is marked down and `Dalli::NetworkError` raised, as for `get`
|
|
10
|
+
- A signal arriving while `Dalli::Compressor` or `Dalli::GzipCompressor` was compressing or decompressing could make Ruby's zlib return before it had finished (ruby/zlib#49). Depending on the Ruby and zlib gem versions, that raised `Zlib::BufError` or `Zlib::DataError`, or stored a truncated value that later failed to decompress. Both compressors now keep finishing the stream until zlib reports its end. `GzipCompressor` no longer goes through `GzipWriter` and `GzipReader`, so it now always returns decompressed values as binary strings, as `Compressor` does (#1299)
|
|
11
|
+
|
|
4
12
|
5.2.7
|
|
5
13
|
==========
|
|
6
14
|
|
data/lib/dalli/compressor.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'zlib'
|
|
4
|
-
require 'stringio'
|
|
5
4
|
|
|
6
5
|
module Dalli
|
|
7
6
|
##
|
|
@@ -10,7 +9,7 @@ module Dalli
|
|
|
10
9
|
##
|
|
11
10
|
class Compressor
|
|
12
11
|
def self.compress(data)
|
|
13
|
-
Zlib::Deflate.
|
|
12
|
+
deflate_fully(Zlib::Deflate.new, data)
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
# DEFLATE can't expand data by more than about 1032:1
|
|
@@ -24,11 +23,51 @@ module Dalli
|
|
|
24
23
|
# as the output passes it, so a small compressed value can't expand into
|
|
25
24
|
# gigabytes of memory.
|
|
26
25
|
def self.decompress(data, max_bytes: nil)
|
|
27
|
-
return Zlib::Inflate.
|
|
26
|
+
return inflate_fully(Zlib::Inflate.new, data) unless may_exceed?(data, max_bytes)
|
|
28
27
|
|
|
29
28
|
inflate_within_limit(Zlib::Inflate.new, data, max_bytes)
|
|
30
29
|
end
|
|
31
30
|
|
|
31
|
+
# Ruby's zlib extension can return from a call before zlib has finished
|
|
32
|
+
# when a signal interrupts it (ruby/zlib#49). One-shot calls like
|
|
33
|
+
# Zlib::Deflate.deflate then raise or, with zlib 3.2.4, return truncated
|
|
34
|
+
# output, so these call finish until the stream has ended.
|
|
35
|
+
def self.deflate_fully(deflater, data)
|
|
36
|
+
finish_stream(deflater, deflater.deflate(data, Zlib::FINISH))
|
|
37
|
+
ensure
|
|
38
|
+
deflater.close
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.inflate_fully(inflater, data)
|
|
42
|
+
finish_stream(inflater, feed(inflater, data) || String.new(encoding: Encoding::BINARY))
|
|
43
|
+
ensure
|
|
44
|
+
inflater.close
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# zlib gem 3.2.3 and earlier retry an interrupted inflate even when it has
|
|
48
|
+
# used up its input, and raise the Z_BUF_ERROR zlib returns for that. The
|
|
49
|
+
# output so far stays in the stream, and finish raises for input that is
|
|
50
|
+
# truly truncated.
|
|
51
|
+
def self.feed(inflater, data, &)
|
|
52
|
+
inflater.inflate(data, &)
|
|
53
|
+
rescue Zlib::BufError
|
|
54
|
+
nil
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.finish_stream(stream, out)
|
|
58
|
+
out << next_chunk(stream) until stream.finished?
|
|
59
|
+
out
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Each finish makes progress, so one that returns nothing means the
|
|
63
|
+
# stream can't end: the compressed input is truncated
|
|
64
|
+
def self.next_chunk(stream)
|
|
65
|
+
chunk = stream.finish
|
|
66
|
+
raise Zlib::BufError, 'buffer error' if chunk.empty?
|
|
67
|
+
|
|
68
|
+
chunk
|
|
69
|
+
end
|
|
70
|
+
|
|
32
71
|
# False when even the largest possible expansion stays within max_bytes,
|
|
33
72
|
# so the value can be inflated in one step
|
|
34
73
|
def self.may_exceed?(data, max_bytes)
|
|
@@ -43,16 +82,15 @@ module Dalli
|
|
|
43
82
|
# with Zlib::Inflate.inflate; finish would return it as output
|
|
44
83
|
break if inflater.finished?
|
|
45
84
|
end
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
append_within_limit(out, inflater.finish, max_bytes)
|
|
85
|
+
append_within_limit(out, next_chunk(inflater), max_bytes) until inflater.finished?
|
|
86
|
+
out
|
|
49
87
|
ensure
|
|
50
88
|
inflater.close
|
|
51
89
|
end
|
|
52
90
|
|
|
53
91
|
# Both yielded and returned output count toward the limit
|
|
54
92
|
def self.inflate_slice(inflater, slice, out, max_bytes)
|
|
55
|
-
rest = inflater
|
|
93
|
+
rest = feed(inflater, slice) { |chunk| append_within_limit(out, chunk, max_bytes) }
|
|
56
94
|
append_within_limit(out, rest, max_bytes)
|
|
57
95
|
end
|
|
58
96
|
|
|
@@ -70,19 +108,18 @@ module Dalli
|
|
|
70
108
|
# entry.
|
|
71
109
|
##
|
|
72
110
|
class GzipCompressor
|
|
111
|
+
# MAX_WBITS + 16 makes zlib write and read the gzip format (and check its CRC)
|
|
112
|
+
WINDOW_BITS = Zlib::MAX_WBITS + 16
|
|
113
|
+
|
|
73
114
|
def self.compress(data)
|
|
74
|
-
|
|
75
|
-
gz = Zlib::GzipWriter.new(io)
|
|
76
|
-
gz.write(data)
|
|
77
|
-
gz.close
|
|
78
|
-
io.string
|
|
115
|
+
Compressor.deflate_fully(Zlib::Deflate.new(Zlib::DEFAULT_COMPRESSION, WINDOW_BITS), data)
|
|
79
116
|
end
|
|
80
117
|
|
|
81
118
|
def self.decompress(data, max_bytes: nil)
|
|
82
|
-
|
|
119
|
+
inflater = Zlib::Inflate.new(WINDOW_BITS)
|
|
120
|
+
return Compressor.inflate_fully(inflater, data) unless Compressor.may_exceed?(data, max_bytes)
|
|
83
121
|
|
|
84
|
-
|
|
85
|
-
Compressor.inflate_within_limit(Zlib::Inflate.new(Zlib::MAX_WBITS + 16), data, max_bytes)
|
|
122
|
+
Compressor.inflate_within_limit(inflater, data, max_bytes)
|
|
86
123
|
end
|
|
87
124
|
end
|
|
88
125
|
end
|
data/lib/dalli/protocol/base.rb
CHANGED
|
@@ -71,13 +71,7 @@ module Dalli
|
|
|
71
71
|
@connection_manager.start_request!
|
|
72
72
|
drain_pending_quiet_responses(opkey)
|
|
73
73
|
response = send(opkey, *args)
|
|
74
|
-
|
|
75
|
-
# end of the quiet block knows this server needs draining
|
|
76
|
-
@connection_manager.mark_quiet_responses_pending! if quiet? && opkey != :noop
|
|
77
|
-
|
|
78
|
-
# pipelined_get/pipelined_get_interleaved emit query but don't read the response(s)
|
|
79
|
-
@connection_manager.finish_request! unless %i[pipelined_get pipelined_get_interleaved].include?(opkey)
|
|
80
|
-
|
|
74
|
+
finish_request(opkey)
|
|
81
75
|
request_completed = true
|
|
82
76
|
response
|
|
83
77
|
rescue Dalli::MarshalError, Dalli::ValueOverMaxSize => e
|
|
@@ -260,6 +254,27 @@ module Dalli
|
|
|
260
254
|
Dalli.logger.warn(URI_CREDENTIAL_WARNING)
|
|
261
255
|
end
|
|
262
256
|
|
|
257
|
+
# Only a request whose reply was read resets the failure count. Otherwise
|
|
258
|
+
# a server that takes set_multi's writes, then drops the connection before
|
|
259
|
+
# the noop's reply, would be back at zero on every retry, never reach
|
|
260
|
+
# socket_max_failures, and be retried forever.
|
|
261
|
+
def finish_request(opkey)
|
|
262
|
+
case opkey
|
|
263
|
+
# Finished by finish_pipeline, once the replies are read
|
|
264
|
+
when :pipelined_get, :pipelined_get_interleaved then nil
|
|
265
|
+
when :pipelined_set, :pipelined_delete then @connection_manager.finish_unanswered_request!
|
|
266
|
+
else
|
|
267
|
+
if quiet? && opkey != :noop
|
|
268
|
+
# Its reply is left on the socket; the end of the quiet block, or
|
|
269
|
+
# the next non-quiet request, reads it
|
|
270
|
+
@connection_manager.mark_quiet_responses_pending!
|
|
271
|
+
@connection_manager.finish_unanswered_request!
|
|
272
|
+
else
|
|
273
|
+
@connection_manager.finish_request!
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
263
278
|
ALLOWED_QUIET_OPS = %i[add replace set delete incr decr append prepend flush noop].freeze
|
|
264
279
|
private_constant :ALLOWED_QUIET_OPS
|
|
265
280
|
|
|
@@ -189,6 +189,15 @@ module Dalli
|
|
|
189
189
|
@fail_count = 0
|
|
190
190
|
end
|
|
191
191
|
|
|
192
|
+
# Ends a request whose reply isn't read with it: a quiet write, or one of
|
|
193
|
+
# set_multi's or delete_multi's writes. The server hasn't answered, so the
|
|
194
|
+
# failure count stays; the noop that reads the replies resets it.
|
|
195
|
+
def finish_unanswered_request!
|
|
196
|
+
raise '[Dalli] No request in progress. This may be a bug in Dalli.' unless @request_in_progress
|
|
197
|
+
|
|
198
|
+
@request_in_progress = false
|
|
199
|
+
end
|
|
200
|
+
|
|
192
201
|
def abort_request!
|
|
193
202
|
@request_in_progress = false
|
|
194
203
|
end
|
data/lib/dalli/version.rb
CHANGED
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: 5.2.
|
|
4
|
+
version: 5.2.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter M. Goldstein
|
|
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
90
|
version: '0'
|
|
91
91
|
requirements: []
|
|
92
|
-
rubygems_version: 4.0.
|
|
92
|
+
rubygems_version: 4.0.24
|
|
93
93
|
specification_version: 4
|
|
94
94
|
summary: High performance memcached client for Ruby
|
|
95
95
|
test_files: []
|