dalli 4.3.10 → 4.3.11
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 +5 -1
- data/README.md +8 -0
- data/lib/dalli/client.rb +1 -0
- data/lib/dalli/pipelined_deleter.rb +3 -3
- data/lib/dalli/pipelined_getter.rb +7 -0
- data/lib/dalli/pipelined_setter.rb +3 -3
- data/lib/dalli/protocol/base.rb +16 -1
- data/lib/dalli/protocol/binary/response_processor.rb +19 -5
- data/lib/dalli/protocol/binary.rb +2 -2
- data/lib/dalli/protocol/connection_manager.rb +9 -3
- data/lib/dalli/protocol/meta/response_processor.rb +26 -4
- data/lib/dalli/protocol/meta.rb +2 -2
- data/lib/dalli/protocol/string_marshaller.rb +3 -1
- data/lib/dalli/protocol/value_marshaller.rb +4 -0
- data/lib/dalli/socket.rb +25 -5
- 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: 69907695ac2c2a065537645099e9b441dea67fda6f3d784cef7f4446bfe65c4f
|
|
4
|
+
data.tar.gz: ffead9d15f6feca0e82c2f2e2194db0051513db82e68bbcc235fcbc934df5280
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e8169758823384e64e5ee1154ba38c1b7498bec6eee179ad885af2355d5a92b3704edc6271c4d9a6c412ca2d82de54988e60c1293ef0c5f6be79e701155fa22d
|
|
7
|
+
data.tar.gz: 752301ede66c25554735a5495a295f302cc3d9ed1a3e8bf37a9fa1a1647bac1baf95639bd4057cfea42c5ede8513465476aab03d227ab4ccc6d87a1adeee19e8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
Dalli Changelog
|
|
2
2
|
=====================
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
4.3.11
|
|
5
5
|
==========
|
|
6
6
|
|
|
7
|
+
Security:
|
|
8
|
+
|
|
9
|
+
- Bound memcached reply headers, incoming value sizes, and response counts, and enforce TLS timeouts for blocking operations (GHSA-5wpc-45jc-6ccc)
|
|
10
|
+
|
|
7
11
|
4.3.10
|
|
8
12
|
==========
|
|
9
13
|
|
data/README.md
CHANGED
|
@@ -45,6 +45,14 @@ Dalli::Client.new('localhost:11211', protocol: :meta)
|
|
|
45
45
|
|
|
46
46
|
## Configuration Options
|
|
47
47
|
|
|
48
|
+
### Response size limit
|
|
49
|
+
|
|
50
|
+
Dalli accepts stored values up to `value_max_bytes` (1 MB by default). Incoming values use the same limit. Set `max_response_bytes` to a positive byte count if an existing memcached deployment stores larger values:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
Dalli::Client.new('localhost:11211', max_response_bytes: 2 * 1024 * 1024)
|
|
54
|
+
```
|
|
55
|
+
|
|
48
56
|
### Namespace
|
|
49
57
|
|
|
50
58
|
Use namespaces to partition your cache and avoid key collisions between different applications or environments:
|
data/lib/dalli/client.rb
CHANGED
|
@@ -27,6 +27,7 @@ module Dalli
|
|
|
27
27
|
# the server configuration.
|
|
28
28
|
#
|
|
29
29
|
# Options:
|
|
30
|
+
# - :max_response_bytes - largest value accepted from a server. Defaults to :value_max_bytes (1 MB by default).
|
|
30
31
|
# - :namespace - prepend each key with this value to provide simple namespacing.
|
|
31
32
|
# - :failover - if a server is down, look for and store values on another server in the ring. Default: true.
|
|
32
33
|
# - :threadsafe - ensure that only one thread is actively using a socket at a time. Default: true.
|
|
@@ -36,7 +36,7 @@ module Dalli
|
|
|
36
36
|
def setup_requests(keys)
|
|
37
37
|
groups = groups_for_keys(keys)
|
|
38
38
|
make_delete_requests(groups)
|
|
39
|
-
groups
|
|
39
|
+
groups
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
##
|
|
@@ -58,8 +58,8 @@ module Dalli
|
|
|
58
58
|
# Sends noop to each server to flush responses and ensure all deletes complete.
|
|
59
59
|
##
|
|
60
60
|
def finish_requests(servers)
|
|
61
|
-
servers.each do |server|
|
|
62
|
-
server.request(:noop)
|
|
61
|
+
servers.each do |server, keys|
|
|
62
|
+
server.request(:noop, keys.size)
|
|
63
63
|
rescue DalliError, NetworkError => e
|
|
64
64
|
Dalli.logger.debug { e.inspect }
|
|
65
65
|
Dalli.logger.debug { "unable to complete pipelined delete on server #{server.name}" }
|
|
@@ -195,6 +195,9 @@ module Dalli
|
|
|
195
195
|
def servers_with_response(servers, timeout)
|
|
196
196
|
return [] if servers.empty?
|
|
197
197
|
|
|
198
|
+
buffered = pending_tls_servers(servers)
|
|
199
|
+
return buffered unless buffered.empty?
|
|
200
|
+
|
|
198
201
|
sockets = servers.map(&:sock)
|
|
199
202
|
readable, = IO.select(sockets, nil, nil, timeout)
|
|
200
203
|
return [] if readable.nil?
|
|
@@ -204,6 +207,10 @@ module Dalli
|
|
|
204
207
|
readable.filter_map { |sock| servers.find { |s| s.sock == sock } }
|
|
205
208
|
end
|
|
206
209
|
|
|
210
|
+
def pending_tls_servers(servers)
|
|
211
|
+
servers.select { |server| server.sock.respond_to?(:pending_data?) && server.sock.pending_data? }
|
|
212
|
+
end
|
|
213
|
+
|
|
207
214
|
def groups_for_keys(*keys)
|
|
208
215
|
keys.flatten!
|
|
209
216
|
keys.map! { |a| @key_manager.validate_key(a.to_s) }
|
|
@@ -47,7 +47,7 @@ module Dalli
|
|
|
47
47
|
pairs = hash.transform_keys { |k| @key_manager.validate_key(k.to_s) }
|
|
48
48
|
groups = groups_for_keys(pairs.keys)
|
|
49
49
|
make_set_requests(groups, pairs, ttl, req_options)
|
|
50
|
-
groups
|
|
50
|
+
groups
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
##
|
|
@@ -73,8 +73,8 @@ module Dalli
|
|
|
73
73
|
# Sends noop to each server to flush responses and ensure all writes complete.
|
|
74
74
|
##
|
|
75
75
|
def finish_requests(servers)
|
|
76
|
-
servers.each do |server|
|
|
77
|
-
server.request(:noop)
|
|
76
|
+
servers.each do |server, keys|
|
|
77
|
+
server.request(:noop, keys.size)
|
|
78
78
|
rescue DalliError, NetworkError => e
|
|
79
79
|
Dalli.logger.debug { e.inspect }
|
|
80
80
|
Dalli.logger.debug { "unable to complete pipelined set on server #{server.name}" }
|
data/lib/dalli/protocol/base.rb
CHANGED
|
@@ -137,6 +137,8 @@ module Dalli
|
|
|
137
137
|
# to the noop at the end of the pipeline
|
|
138
138
|
finish_pipeline && break if status && key.nil?
|
|
139
139
|
|
|
140
|
+
check_pipeline_response_count!(false)
|
|
141
|
+
|
|
140
142
|
# A key that wasn't requested means the replies are out of step
|
|
141
143
|
# (see expect_reply_keys): keep what was read so far, drop the rest
|
|
142
144
|
if unexpected_reply_key?(key)
|
|
@@ -327,7 +329,7 @@ module Dalli
|
|
|
327
329
|
# Non-blocking read and processing of any available pipeline responses.
|
|
328
330
|
# Used during interleaved pipelined gets to prevent buffer deadlock.
|
|
329
331
|
# Populates the provided results hash directly to avoid allocation overhead.
|
|
330
|
-
def drain_pipeline_responses(results)
|
|
332
|
+
def drain_pipeline_responses(results) # rubocop:disable Metrics/CyclomaticComplexity
|
|
331
333
|
return unless connected?
|
|
332
334
|
|
|
333
335
|
# Non-blocking check if socket has data available
|
|
@@ -341,6 +343,8 @@ module Dalli
|
|
|
341
343
|
status, cas, key, value = response_buffer.process_single_getk_response
|
|
342
344
|
break if status.nil? # No complete response available
|
|
343
345
|
|
|
346
|
+
check_pipeline_response_count!(status && key.nil?)
|
|
347
|
+
|
|
344
348
|
# Handled by the next pipeline_next_responses, once sending is done
|
|
345
349
|
if unexpected_reply_key?(key)
|
|
346
350
|
@pipeline_out_of_step = true
|
|
@@ -374,9 +378,20 @@ module Dalli
|
|
|
374
378
|
# other clients created, on memcached versions with the behavior.
|
|
375
379
|
def expect_reply_keys(keys)
|
|
376
380
|
@pipeline_out_of_step = false
|
|
381
|
+
@expected_response_count = keys.size
|
|
382
|
+
@pipeline_response_count = 0
|
|
377
383
|
@expected_reply_keys = (keys.to_set { |k| reply_key_form(k) } if @verify_reply_keys)
|
|
378
384
|
end
|
|
379
385
|
|
|
386
|
+
def check_pipeline_response_count!(terminating)
|
|
387
|
+
return if terminating
|
|
388
|
+
|
|
389
|
+
@pipeline_response_count += 1
|
|
390
|
+
return if @pipeline_response_count <= @expected_response_count
|
|
391
|
+
|
|
392
|
+
raise Dalli::DalliError, 'Too many get_multi replies'
|
|
393
|
+
end
|
|
394
|
+
|
|
380
395
|
def unexpected_reply_key?(key)
|
|
381
396
|
!key.nil? && @expected_reply_keys && !@expected_reply_keys.include?(reply_key_form(key))
|
|
382
397
|
end
|
|
@@ -9,6 +9,8 @@ module Dalli
|
|
|
9
9
|
# and parsing into local values. Handles errors on unexpected values.
|
|
10
10
|
##
|
|
11
11
|
class ResponseProcessor
|
|
12
|
+
MAX_STATS_ENTRIES = 10_000
|
|
13
|
+
MAX_QUIET_RESPONSES = 100_000
|
|
12
14
|
# Response codes taken from:
|
|
13
15
|
# https://github.com/memcached/memcached/wiki/BinaryProtocolRevamped#response-status
|
|
14
16
|
RESPONSE_CODES = {
|
|
@@ -42,6 +44,7 @@ module Dalli
|
|
|
42
44
|
|
|
43
45
|
def read_response
|
|
44
46
|
resp_header = ResponseHeader.new(read_header)
|
|
47
|
+
check_body_size!(resp_header)
|
|
45
48
|
body = read(resp_header.body_len) if resp_header.body_len.positive?
|
|
46
49
|
[resp_header, body]
|
|
47
50
|
end
|
|
@@ -122,11 +125,15 @@ module Dalli
|
|
|
122
125
|
|
|
123
126
|
def stats
|
|
124
127
|
hash = {}
|
|
128
|
+
replies = 0
|
|
125
129
|
loop do
|
|
126
130
|
resp_header, body = read_response
|
|
127
131
|
# This is the response to the terminating noop / end of stat
|
|
128
132
|
return hash if resp_header.ok? && resp_header.key_len.zero?
|
|
129
133
|
|
|
134
|
+
replies += 1
|
|
135
|
+
raise Dalli::DalliError, 'Too many stats replies' if replies > MAX_STATS_ENTRIES
|
|
136
|
+
|
|
130
137
|
# Ignore any responses with non-zero status codes,
|
|
131
138
|
# such as errors from set operations. That allows
|
|
132
139
|
# this code to be used at the end of a multi
|
|
@@ -150,11 +157,15 @@ module Dalli
|
|
|
150
157
|
generic_response
|
|
151
158
|
end
|
|
152
159
|
|
|
153
|
-
def consume_all_responses_until_noop
|
|
160
|
+
def consume_all_responses_until_noop(max_responses = MAX_QUIET_RESPONSES)
|
|
161
|
+
replies = 0
|
|
154
162
|
loop do
|
|
155
163
|
resp_header, = read_response
|
|
156
164
|
# This is the response to the terminating noop / end of stat
|
|
157
165
|
return true if resp_header.ok? && resp_header.key_len.zero?
|
|
166
|
+
|
|
167
|
+
replies += 1
|
|
168
|
+
raise Dalli::DalliError, 'Too many quiet replies' if replies > max_responses
|
|
158
169
|
end
|
|
159
170
|
end
|
|
160
171
|
|
|
@@ -188,6 +199,7 @@ module Dalli
|
|
|
188
199
|
resp_header = ResponseHeader.new(buf)
|
|
189
200
|
body_len = resp_header.body_len
|
|
190
201
|
validate_auth_format(resp_header.extra_len, body_len)
|
|
202
|
+
check_body_size!(resp_header)
|
|
191
203
|
content = read(body_len) if body_len.positive?
|
|
192
204
|
[resp_header.status, content]
|
|
193
205
|
end
|
|
@@ -207,8 +219,11 @@ module Dalli
|
|
|
207
219
|
# buffer wait for (and accumulate) that many bytes.
|
|
208
220
|
MAX_BODY_BYTES = 1024 * 1024 * 1024
|
|
209
221
|
|
|
210
|
-
def check_body_size!(
|
|
211
|
-
|
|
222
|
+
def check_body_size!(header)
|
|
223
|
+
size = header.body_len
|
|
224
|
+
value_size = size - header.extra_len - header.key_len
|
|
225
|
+
limit = [MAX_BODY_BYTES, @value_marshaller.max_response_bytes].min
|
|
226
|
+
return if size <= MAX_BODY_BYTES && value_size.between?(0, limit)
|
|
212
227
|
|
|
213
228
|
raise Dalli::DalliError, "Reply body size #{size} is out of range"
|
|
214
229
|
end
|
|
@@ -219,6 +234,7 @@ module Dalli
|
|
|
219
234
|
|
|
220
235
|
resp_header = ResponseHeader.new(buf.byteslice(offset, ResponseHeader::SIZE))
|
|
221
236
|
body_len = resp_header.body_len
|
|
237
|
+
check_body_size!(resp_header)
|
|
222
238
|
|
|
223
239
|
# We have a complete response that has no body.
|
|
224
240
|
# This is either the response to the terminating
|
|
@@ -226,8 +242,6 @@ module Dalli
|
|
|
226
242
|
# error response that needs to be discarded.
|
|
227
243
|
return [ResponseHeader::SIZE, resp_header.ok?, resp_header.cas, nil, nil] if body_len.zero?
|
|
228
244
|
|
|
229
|
-
check_body_size!(body_len)
|
|
230
|
-
|
|
231
245
|
resp_size = ResponseHeader::SIZE + body_len
|
|
232
246
|
# The header is in the buffer, but the body is not. As we don't have
|
|
233
247
|
# a complete response, don't advance the buffer
|
|
@@ -159,9 +159,9 @@ module Dalli
|
|
|
159
159
|
|
|
160
160
|
# Noop is a keepalive operation but also used to demarcate the end of a set of pipelined commands.
|
|
161
161
|
# We need to read all the responses at once.
|
|
162
|
-
def noop
|
|
162
|
+
def noop(max_responses = ResponseProcessor::MAX_QUIET_RESPONSES)
|
|
163
163
|
write_noop
|
|
164
|
-
result = response_processor.consume_all_responses_until_noop
|
|
164
|
+
result = response_processor.consume_all_responses_until_noop(max_responses)
|
|
165
165
|
# Everything up to and including the noop reply has been read
|
|
166
166
|
@connection_manager.clear_quiet_responses_pending!
|
|
167
167
|
result
|
|
@@ -200,7 +200,7 @@ module Dalli
|
|
|
200
200
|
|
|
201
201
|
def read_line
|
|
202
202
|
flush_write_buffer
|
|
203
|
-
data = @sock.gets("\r\n", MAX_LINE_BYTES)
|
|
203
|
+
data = with_tls_timeout { @sock.gets("\r\n", MAX_LINE_BYTES) }
|
|
204
204
|
error_on_request!('EOF in read_line') if data.nil?
|
|
205
205
|
# Without its CRLF the line either ran past MAX_LINE_BYTES or was cut
|
|
206
206
|
# short by EOF; either way the connection is out of step
|
|
@@ -224,7 +224,7 @@ module Dalli
|
|
|
224
224
|
def read(count)
|
|
225
225
|
check_read_size!(count)
|
|
226
226
|
flush_write_buffer
|
|
227
|
-
@sock.readfull(count)
|
|
227
|
+
with_tls_timeout { @sock.readfull(count) }
|
|
228
228
|
rescue SystemCallError, *TIMEOUT_ERRORS, *SSL_ERRORS, EOFError => e
|
|
229
229
|
error_on_request!(e)
|
|
230
230
|
end
|
|
@@ -354,10 +354,16 @@ module Dalli
|
|
|
354
354
|
def flush_write_buffer
|
|
355
355
|
return if @write_buffer.empty?
|
|
356
356
|
|
|
357
|
-
@sock.write(@write_buffer.size == 1 ? @write_buffer.first : joined_write_buffer)
|
|
357
|
+
with_tls_timeout { @sock.write(@write_buffer.size == 1 ? @write_buffer.first : joined_write_buffer) }
|
|
358
358
|
discard_write_buffer
|
|
359
359
|
end
|
|
360
360
|
|
|
361
|
+
def with_tls_timeout
|
|
362
|
+
return yield unless @sock.is_a?(Dalli::Socket::SSLSocket)
|
|
363
|
+
|
|
364
|
+
Timeout.timeout(socket_timeout) { yield } # rubocop:disable Style/ExplicitBlockArgument
|
|
365
|
+
end
|
|
366
|
+
|
|
361
367
|
# Joined as bytes: requests can mix UTF-8 and binary strings, which
|
|
362
368
|
# String#<< refuses to combine when both hold non-ASCII bytes
|
|
363
369
|
if String.method_defined?(:append_as_bytes)
|
|
@@ -9,6 +9,9 @@ module Dalli
|
|
|
9
9
|
# and parsing into local values. Handles errors on unexpected values.
|
|
10
10
|
##
|
|
11
11
|
class ResponseProcessor
|
|
12
|
+
MAX_HEADER_BYTES = 8 * 1024
|
|
13
|
+
MAX_STATS_ENTRIES = 10_000
|
|
14
|
+
MAX_QUIET_RESPONSES = 100_000
|
|
12
15
|
EN = 'EN'
|
|
13
16
|
END_TOKEN = 'END'
|
|
14
17
|
EX = 'EX'
|
|
@@ -125,7 +128,11 @@ module Dalli
|
|
|
125
128
|
def stats
|
|
126
129
|
tokens = error_on_unexpected!([END_TOKEN, STAT])
|
|
127
130
|
values = {}
|
|
131
|
+
replies = 0
|
|
128
132
|
while tokens.first != END_TOKEN
|
|
133
|
+
replies += 1
|
|
134
|
+
raise Dalli::DalliError, 'Too many stats replies' if replies > MAX_STATS_ENTRIES
|
|
135
|
+
|
|
129
136
|
values[tokens[1]] = tokens[2]
|
|
130
137
|
tokens = next_line_to_tokens
|
|
131
138
|
end
|
|
@@ -149,10 +156,16 @@ module Dalli
|
|
|
149
156
|
tokens.last
|
|
150
157
|
end
|
|
151
158
|
|
|
152
|
-
def consume_all_responses_until_mn
|
|
159
|
+
def consume_all_responses_until_mn(max_responses = MAX_QUIET_RESPONSES)
|
|
153
160
|
tokens = next_line_to_tokens
|
|
154
161
|
|
|
155
|
-
|
|
162
|
+
replies = 0
|
|
163
|
+
while tokens.first != MN
|
|
164
|
+
replies += 1
|
|
165
|
+
raise Dalli::DalliError, 'Too many quiet replies' if replies > max_responses
|
|
166
|
+
|
|
167
|
+
tokens = next_line_to_tokens
|
|
168
|
+
end
|
|
156
169
|
true
|
|
157
170
|
end
|
|
158
171
|
|
|
@@ -175,9 +188,10 @@ module Dalli
|
|
|
175
188
|
# The remaining three values in the array are the ResponseHeader,
|
|
176
189
|
# key, and value.
|
|
177
190
|
##
|
|
178
|
-
def getk_response_from_buffer(buf, offset = 0)
|
|
191
|
+
def getk_response_from_buffer(buf, offset = 0) # rubocop:disable Metrics/AbcSize
|
|
179
192
|
# Find the header terminator starting from offset
|
|
180
193
|
term_idx = buf.index(TERMINATOR, offset)
|
|
194
|
+
check_header_size!(buf, offset, term_idx)
|
|
181
195
|
return [0, nil, nil, nil, nil] unless term_idx
|
|
182
196
|
|
|
183
197
|
header = buf.byteslice(offset, term_idx - offset)
|
|
@@ -205,6 +219,13 @@ module Dalli
|
|
|
205
219
|
full_response_from_buffer(tokens, body, resp_size)
|
|
206
220
|
end
|
|
207
221
|
|
|
222
|
+
def check_header_size!(buf, offset, term_idx)
|
|
223
|
+
size = (term_idx || buf.bytesize) - offset
|
|
224
|
+
return if size + TERMINATOR.bytesize <= MAX_HEADER_BYTES
|
|
225
|
+
|
|
226
|
+
raise Dalli::DalliError, 'Reply header exceeds 8 KiB'
|
|
227
|
+
end
|
|
228
|
+
|
|
208
229
|
# memcached can't store an item larger than 1 GiB (its -I maximum). A
|
|
209
230
|
# pipelined reply claiming an impossible size would otherwise have the
|
|
210
231
|
# buffer wait for (and accumulate) that many bytes.
|
|
@@ -216,7 +237,8 @@ module Dalli
|
|
|
216
237
|
end
|
|
217
238
|
|
|
218
239
|
def check_value_size!(size)
|
|
219
|
-
|
|
240
|
+
limit = @value_marshaller.max_response_bytes
|
|
241
|
+
return if size >= 0 && size <= MAX_VALUE_BYTES && size <= limit # rubocop:disable Style/ComparableBetween
|
|
220
242
|
|
|
221
243
|
raise Dalli::DalliError, "Reply value size #{size} is out of range"
|
|
222
244
|
end
|
data/lib/dalli/protocol/meta.rb
CHANGED
|
@@ -261,9 +261,9 @@ module Dalli
|
|
|
261
261
|
|
|
262
262
|
# Noop is a keepalive operation but also used to demarcate the end of a set of pipelined commands.
|
|
263
263
|
# We need to read all the responses at once.
|
|
264
|
-
def noop
|
|
264
|
+
def noop(max_responses = ResponseProcessor::MAX_QUIET_RESPONSES)
|
|
265
265
|
write_noop
|
|
266
|
-
result = response_processor.consume_all_responses_until_mn
|
|
266
|
+
result = response_processor.consume_all_responses_until_mn(max_responses)
|
|
267
267
|
# Everything up to and including the MN has been read
|
|
268
268
|
@connection_manager.clear_quiet_responses_pending!
|
|
269
269
|
result
|
|
@@ -14,12 +14,14 @@ module Dalli
|
|
|
14
14
|
value_max_bytes: 1024 * 1024
|
|
15
15
|
}.freeze
|
|
16
16
|
|
|
17
|
-
attr_reader :value_max_bytes
|
|
17
|
+
attr_reader :value_max_bytes, :max_response_bytes
|
|
18
18
|
|
|
19
19
|
def initialize(client_options)
|
|
20
20
|
@value_max_bytes = client_options.fetch(:value_max_bytes) do
|
|
21
21
|
DEFAULTS.fetch(:value_max_bytes)
|
|
22
22
|
end.to_i
|
|
23
|
+
@max_response_bytes = Integer(client_options.fetch(:max_response_bytes, @value_max_bytes))
|
|
24
|
+
raise ArgumentError, 'max_response_bytes must be positive' unless @max_response_bytes.positive?
|
|
23
25
|
end
|
|
24
26
|
|
|
25
27
|
def store(key, value, _options = nil)
|
|
@@ -28,6 +28,8 @@ module Dalli
|
|
|
28
28
|
|
|
29
29
|
@marshal_options =
|
|
30
30
|
DEFAULTS.merge(client_options.slice(*OPTIONS))
|
|
31
|
+
@max_response_bytes = Integer(client_options.fetch(:max_response_bytes, value_max_bytes))
|
|
32
|
+
raise ArgumentError, 'max_response_bytes must be positive' unless @max_response_bytes.positive?
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
def store(key, value, options = nil)
|
|
@@ -48,6 +50,8 @@ module Dalli
|
|
|
48
50
|
@marshal_options[:value_max_bytes]
|
|
49
51
|
end
|
|
50
52
|
|
|
53
|
+
attr_reader :max_response_bytes
|
|
54
|
+
|
|
51
55
|
def error_if_over_max_value_bytes(key, value)
|
|
52
56
|
return if value.bytesize <= value_max_bytes
|
|
53
57
|
|
data/lib/dalli/socket.rb
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require 'openssl'
|
|
4
4
|
require 'rbconfig'
|
|
5
|
+
require 'timeout'
|
|
5
6
|
|
|
6
7
|
module Dalli
|
|
7
8
|
##
|
|
@@ -12,6 +13,8 @@ module Dalli
|
|
|
12
13
|
# Common methods for all socket implementations.
|
|
13
14
|
##
|
|
14
15
|
module InstanceMethods
|
|
16
|
+
MAX_AVAILABLE_BYTES = 8196 * 8
|
|
17
|
+
|
|
15
18
|
def readfull(count)
|
|
16
19
|
value = String.new(capacity: count + 1)
|
|
17
20
|
loop do
|
|
@@ -24,16 +27,21 @@ module Dalli
|
|
|
24
27
|
|
|
25
28
|
def read_available
|
|
26
29
|
value = +''
|
|
27
|
-
|
|
28
|
-
result = read_nonblock(8196, exception: false)
|
|
30
|
+
while value.bytesize < MAX_AVAILABLE_BYTES
|
|
31
|
+
result = read_nonblock([8196, MAX_AVAILABLE_BYTES - value.bytesize].min, exception: false)
|
|
29
32
|
break if WAIT_RCS.include?(result)
|
|
30
33
|
raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}" unless result
|
|
31
34
|
|
|
32
35
|
value << result
|
|
36
|
+
break if result.bytesize < 8196 && !buffered_data?
|
|
33
37
|
end
|
|
34
38
|
value
|
|
35
39
|
end
|
|
36
40
|
|
|
41
|
+
def buffered_data?
|
|
42
|
+
false
|
|
43
|
+
end
|
|
44
|
+
|
|
37
45
|
WAIT_RCS = %i[wait_writable wait_readable].freeze
|
|
38
46
|
|
|
39
47
|
def append_to_buffer?(result)
|
|
@@ -64,6 +72,14 @@ module Dalli
|
|
|
64
72
|
class SSLSocket < ::OpenSSL::SSL::SSLSocket
|
|
65
73
|
include Dalli::Socket::InstanceMethods
|
|
66
74
|
|
|
75
|
+
def pending_data?
|
|
76
|
+
pending.positive? || (@rbuffer && !@rbuffer.empty?)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def buffered_data?
|
|
80
|
+
RUBY_ENGINE == 'jruby' || pending_data?
|
|
81
|
+
end
|
|
82
|
+
|
|
67
83
|
def options
|
|
68
84
|
io.options
|
|
69
85
|
end
|
|
@@ -101,7 +117,11 @@ module Dalli
|
|
|
101
117
|
sock.options = { host: host, port: port }.merge(options)
|
|
102
118
|
init_socket_options(sock, options)
|
|
103
119
|
|
|
104
|
-
|
|
120
|
+
if options[:ssl_context]
|
|
121
|
+
wrapping_ssl_socket(sock, host, options[:ssl_context], options[:socket_timeout])
|
|
122
|
+
else
|
|
123
|
+
sock
|
|
124
|
+
end
|
|
105
125
|
end
|
|
106
126
|
end
|
|
107
127
|
|
|
@@ -183,13 +203,13 @@ module Dalli
|
|
|
183
203
|
|
|
184
204
|
# Closes the TCP socket if the handshake fails or times out, so a failed
|
|
185
205
|
# attempt doesn't hold a file descriptor until GC.
|
|
186
|
-
def self.wrapping_ssl_socket(tcp_socket, host, ssl_context)
|
|
206
|
+
def self.wrapping_ssl_socket(tcp_socket, host, ssl_context, socket_timeout = nil)
|
|
187
207
|
warn_if_unverified(ssl_context)
|
|
188
208
|
connected = false
|
|
189
209
|
ssl_socket = Dalli::Socket::SSLSocket.new(tcp_socket, ssl_context)
|
|
190
210
|
ssl_socket.hostname = host
|
|
191
211
|
ssl_socket.sync_close = true
|
|
192
|
-
ssl_socket.connect
|
|
212
|
+
Timeout.timeout(socket_timeout) { ssl_socket.connect }
|
|
193
213
|
connected = true
|
|
194
214
|
ssl_socket
|
|
195
215
|
ensure
|
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: 4.3.
|
|
4
|
+
version: 4.3.11
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter M. Goldstein
|
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '0'
|
|
96
96
|
requirements: []
|
|
97
|
-
rubygems_version: 4.0.
|
|
97
|
+
rubygems_version: 4.0.24
|
|
98
98
|
specification_version: 4
|
|
99
99
|
summary: High performance memcached client for Ruby
|
|
100
100
|
test_files: []
|