dalli 5.2.8 → 5.2.10
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 +14 -0
- data/README.md +2 -0
- data/lib/dalli/client.rb +2 -0
- data/lib/dalli/pipelined_getter.rb +10 -0
- data/lib/dalli/protocol/base.rb +11 -1
- data/lib/dalli/protocol/connection_manager.rb +13 -3
- data/lib/dalli/protocol/meta.rb +15 -5
- data/lib/dalli/protocol/response_processor.rb +45 -6
- data/lib/dalli/protocol/string_marshaller.rb +3 -1
- data/lib/dalli/protocol/value_marshaller.rb +4 -0
- data/lib/dalli/socket.rb +24 -6
- data/lib/dalli/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 795b719ba3bbc4279d013ab426c56cead970184b9ac0bd7e6712cd416b763554
|
|
4
|
+
data.tar.gz: 8991510ae05ce28e79132a734452533f232b5b04ae97e6cffa80b872189bbd23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6fe2ee231edde489259c8fbecbb33a9c083becd1a398d1a8488f9606c2dc2a115a6fb296ca8f8ce67945c550ac1a21ffd8b2f4d8b75b08f78fb855048427529e
|
|
7
|
+
data.tar.gz: 783534ab9926133bd90a865a47ec2bb65cd25beb4fa6fdc497c88e37a079b1101086870cf30c390615cb01d4f428c535c30350189d29368c1dda426de215b81a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
Dalli Changelog
|
|
2
2
|
=====================
|
|
3
3
|
|
|
4
|
+
5.2.10
|
|
5
|
+
==========
|
|
6
|
+
|
|
7
|
+
Security:
|
|
8
|
+
|
|
9
|
+
- Security fixes; details will follow in the advisory.
|
|
10
|
+
|
|
11
|
+
5.2.9
|
|
12
|
+
==========
|
|
13
|
+
|
|
14
|
+
Security:
|
|
15
|
+
|
|
16
|
+
- Bound memcached reply headers, incoming value sizes, and response counts, and enforce TLS timeouts for blocking operations (GHSA-5wpc-45jc-6ccc)
|
|
17
|
+
|
|
4
18
|
5.2.8
|
|
5
19
|
==========
|
|
6
20
|
|
data/README.md
CHANGED
|
@@ -70,6 +70,8 @@ Dalli::Client.new('localhost:11211', value_max_bytes: 2 * 1024 * 1024)
|
|
|
70
70
|
|
|
71
71
|
memcached's limit covers the whole item, so Dalli checks the stored (serialized and compressed) value plus the key plus 63 bytes of per-item overhead against `value_max_bytes`, and raises `Dalli::ValueOverMaxSize` before sending anything larger. With the defaults, the largest value you can store under a 10-byte key is 1,048,576 - 10 - 63 = 1,048,503 bytes.
|
|
72
72
|
|
|
73
|
+
Dalli also limits the size of values it reads to `value_max_bytes`. If another client writes larger items that this client needs to read, set `max_response_bytes` explicitly. Keep it no higher than the largest item size you intend to accept from the server.
|
|
74
|
+
|
|
73
75
|
### Deferred Draining
|
|
74
76
|
|
|
75
77
|
By default, a `quiet` (or `multi`) block ends by waiting for the replies memcached still sends for its quiet requests, one round trip for each server the block wrote to. With `defer_drain: true`, the block returns without waiting:
|
data/lib/dalli/client.rb
CHANGED
|
@@ -39,6 +39,8 @@ module Dalli
|
|
|
39
39
|
# memcached, Dalli counts the key and 63 bytes of item overhead against this limit along
|
|
40
40
|
# with the (serialized, compressed) value, so the largest value that can be stored is
|
|
41
41
|
# value_max_bytes - key bytesize - 63. Larger values raise Dalli::ValueOverMaxSize.
|
|
42
|
+
# - :max_response_bytes - largest value accepted from a server. Defaults to :value_max_bytes (1MB by default).
|
|
43
|
+
# Set this explicitly when reading larger items written by another client.
|
|
42
44
|
# - :serializer - defaults to Marshal
|
|
43
45
|
# - :compressor - defaults to Dalli::Compressor, a Zlib-based implementation
|
|
44
46
|
# - :cache_nils - defaults to false, if true Dalli will not treat cached nil values as 'not found' for
|
|
@@ -228,6 +228,16 @@ module Dalli
|
|
|
228
228
|
def servers_with_response(servers, timeout)
|
|
229
229
|
return [] if servers.empty?
|
|
230
230
|
|
|
231
|
+
# A bounded read can stop while OpenSSL still holds decrypted bytes.
|
|
232
|
+
# IO.select only sees the underlying socket, so process those bytes
|
|
233
|
+
# before waiting for another network event.
|
|
234
|
+
buffered = nil
|
|
235
|
+
servers.each do |server|
|
|
236
|
+
sock = server.sock
|
|
237
|
+
(buffered ||= []) << server if sock.respond_to?(:pending_data?) && sock.pending_data?
|
|
238
|
+
end
|
|
239
|
+
return buffered if buffered
|
|
240
|
+
|
|
231
241
|
sockets = servers.map(&:sock)
|
|
232
242
|
readable, = IO.select(sockets, nil, nil, timeout)
|
|
233
243
|
return [] if readable.nil?
|
data/lib/dalli/protocol/base.rb
CHANGED
|
@@ -177,6 +177,9 @@ module Dalli
|
|
|
177
177
|
# to the noop at the end of the pipeline
|
|
178
178
|
finish_pipeline && break if status && key.nil?
|
|
179
179
|
|
|
180
|
+
@pipeline_response_count += 1
|
|
181
|
+
raise Dalli::DalliError, 'Too many get_multi replies' if @pipeline_response_count > @expected_response_count
|
|
182
|
+
|
|
180
183
|
# A key that wasn't requested means the replies are out of step
|
|
181
184
|
# (see expect_reply_keys): keep what was read so far, drop the rest
|
|
182
185
|
if unexpected_reply_key?(key)
|
|
@@ -217,6 +220,8 @@ module Dalli
|
|
|
217
220
|
response_buffer.clear
|
|
218
221
|
@pipeline_out_of_step = false
|
|
219
222
|
@expected_reply_keys = nil
|
|
223
|
+
@expected_response_count = nil
|
|
224
|
+
@pipeline_response_count = nil
|
|
220
225
|
@connection_manager.abort_request!
|
|
221
226
|
return true unless connected?
|
|
222
227
|
|
|
@@ -422,7 +427,7 @@ module Dalli
|
|
|
422
427
|
# Non-blocking read and processing of any available pipeline responses.
|
|
423
428
|
# Used during interleaved pipelined gets to prevent buffer deadlock.
|
|
424
429
|
# Populates the provided results hash directly to avoid allocation overhead.
|
|
425
|
-
def drain_pipeline_responses(results)
|
|
430
|
+
def drain_pipeline_responses(results) # rubocop:disable Metrics/CyclomaticComplexity
|
|
426
431
|
return unless connected?
|
|
427
432
|
|
|
428
433
|
# Non-blocking check if socket has data available
|
|
@@ -436,6 +441,9 @@ module Dalli
|
|
|
436
441
|
status, cas, key, value = response_buffer.process_single_getk_response
|
|
437
442
|
break if status.nil? # No complete response available
|
|
438
443
|
|
|
444
|
+
@pipeline_response_count += 1
|
|
445
|
+
raise Dalli::DalliError, 'Too many get_multi replies' if @pipeline_response_count > @expected_response_count
|
|
446
|
+
|
|
439
447
|
# Handled by the next pipeline_next_responses, once sending is done
|
|
440
448
|
if unexpected_reply_key?(key)
|
|
441
449
|
@pipeline_out_of_step = true
|
|
@@ -469,6 +477,8 @@ module Dalli
|
|
|
469
477
|
# other clients created, on memcached versions with the behavior.
|
|
470
478
|
def expect_reply_keys(keys)
|
|
471
479
|
@pipeline_out_of_step = false
|
|
480
|
+
@expected_response_count = keys.size
|
|
481
|
+
@pipeline_response_count = 0
|
|
472
482
|
@expected_reply_keys = (keys.to_set { |k| reply_key_form(k) } if @verify_reply_keys)
|
|
473
483
|
end
|
|
474
484
|
|
|
@@ -213,7 +213,7 @@ module Dalli
|
|
|
213
213
|
|
|
214
214
|
def read_line
|
|
215
215
|
flush_write_buffer
|
|
216
|
-
data = @sock.gets("\r\n", MAX_LINE_BYTES)
|
|
216
|
+
data = timed_tls_operation { @sock.gets("\r\n", MAX_LINE_BYTES) }
|
|
217
217
|
error_on_request!('EOF in read_line') if data.nil?
|
|
218
218
|
# Without its CRLF the line either ran past MAX_LINE_BYTES or was cut
|
|
219
219
|
# short by EOF; either way the connection is out of step
|
|
@@ -378,13 +378,23 @@ module Dalli
|
|
|
378
378
|
|
|
379
379
|
private
|
|
380
380
|
|
|
381
|
+
# Ruby 3.3's default OpenSSL can block past IO#timeout= on the TCP
|
|
382
|
+
# socket. Bound the blocking TLS call itself; error_on_request! closes
|
|
383
|
+
# the connection after the Timeout::Error, so a partial reply or write
|
|
384
|
+
# is never reused.
|
|
385
|
+
def timed_tls_operation(&)
|
|
386
|
+
return yield unless @sock.is_a?(Dalli::Socket::SSLSocket)
|
|
387
|
+
|
|
388
|
+
Timeout.timeout(socket_timeout, &)
|
|
389
|
+
end
|
|
390
|
+
|
|
381
391
|
# One write per flush. A TLS socket sends each argument of
|
|
382
392
|
# write(*parts) as its own record and system call, so the parts are
|
|
383
393
|
# joined first.
|
|
384
394
|
def flush_write_buffer
|
|
385
395
|
return if @write_buffer.empty?
|
|
386
396
|
|
|
387
|
-
@sock.write(@write_buffer.size == 1 ? @write_buffer.first : joined_write_buffer)
|
|
397
|
+
timed_tls_operation { @sock.write(@write_buffer.size == 1 ? @write_buffer.first : joined_write_buffer) }
|
|
388
398
|
discard_write_buffer
|
|
389
399
|
end
|
|
390
400
|
|
|
@@ -417,7 +427,7 @@ module Dalli
|
|
|
417
427
|
# error_on_request!, which closes the dirty socket for a retry on a fresh
|
|
418
428
|
# connection (and preserves the $ERROR_INFO context down! relies on).
|
|
419
429
|
def read_bytes(count)
|
|
420
|
-
buffer = @sock.read(count)
|
|
430
|
+
buffer = timed_tls_operation { @sock.read(count) }
|
|
421
431
|
return buffer if buffer && buffer.bytesize == count
|
|
422
432
|
|
|
423
433
|
raise EOFError, "EOF reading #{count} bytes; received #{buffer ? buffer.bytesize : 0}"
|
data/lib/dalli/protocol/meta.rb
CHANGED
|
@@ -229,7 +229,7 @@ module Dalli
|
|
|
229
229
|
|
|
230
230
|
def finish_pipelined_delete(sent)
|
|
231
231
|
write_noop
|
|
232
|
-
sent - response_processor.pipelined_delete_non_deletions
|
|
232
|
+
sent - response_processor.pipelined_delete_non_deletions(sent)
|
|
233
233
|
end
|
|
234
234
|
|
|
235
235
|
# Arithmetic Commands
|
|
@@ -363,14 +363,19 @@ module Dalli
|
|
|
363
363
|
def read_multi_metadata_responses(is_raw, keys)
|
|
364
364
|
expect_reply_keys(keys)
|
|
365
365
|
hash = {}
|
|
366
|
+
replies = 0
|
|
366
367
|
while (line = @connection_manager.read_line)
|
|
367
368
|
break if line.start_with?('MN')
|
|
369
|
+
|
|
370
|
+
replies += 1
|
|
371
|
+
raise Dalli::DalliError, 'Too many get_multi replies' if replies > keys.size
|
|
372
|
+
|
|
368
373
|
next unless line.start_with?('VA ')
|
|
369
374
|
|
|
370
375
|
tokens = line.chomp!(TERMINATOR).split
|
|
371
376
|
size = tokens[1].to_i
|
|
372
377
|
response_processor.check_value_size!(size)
|
|
373
|
-
value = @connection_manager.read(size + TERMINATOR.bytesize)
|
|
378
|
+
value = response_processor.strip_value_terminator!(@connection_manager.read(size + TERMINATOR.bytesize))
|
|
374
379
|
stale = response_processor.stale_from_tokens(tokens)
|
|
375
380
|
cas = response_processor.cas_from_tokens(tokens)
|
|
376
381
|
bitflags = is_raw ? 0 : response_processor.bitflags_from_tokens(tokens)
|
|
@@ -387,8 +392,13 @@ module Dalli
|
|
|
387
392
|
def read_multi_get_responses(is_raw, keys)
|
|
388
393
|
expect_reply_keys(keys)
|
|
389
394
|
hash = {}
|
|
395
|
+
replies = 0
|
|
390
396
|
while (line = @connection_manager.read_line)
|
|
391
397
|
break if line.start_with?('MN')
|
|
398
|
+
|
|
399
|
+
replies += 1
|
|
400
|
+
raise Dalli::DalliError, 'Too many get_multi replies' if replies > keys.size
|
|
401
|
+
|
|
392
402
|
next unless line.start_with?('VA ')
|
|
393
403
|
|
|
394
404
|
key, value = parse_multi_get_value(line, is_raw)
|
|
@@ -411,7 +421,7 @@ module Dalli
|
|
|
411
421
|
processor = response_processor
|
|
412
422
|
size = processor.size_from_va_line(line)
|
|
413
423
|
processor.check_value_size!(size)
|
|
414
|
-
value = @connection_manager.read(size + TERMINATOR.bytesize)
|
|
424
|
+
value = processor.strip_value_terminator!(@connection_manager.read(size + TERMINATOR.bytesize))
|
|
415
425
|
key = processor.key_from_va_line(line)
|
|
416
426
|
return unless key
|
|
417
427
|
|
|
@@ -439,7 +449,7 @@ module Dalli
|
|
|
439
449
|
buffer = RequestFormatter.multi_meta_set(entries, ttl: ttl, **routing_token_kwargs(req_options))
|
|
440
450
|
flushed_write(buffer)
|
|
441
451
|
buffer.clear
|
|
442
|
-
response_processor.consume_all_responses_until_mn
|
|
452
|
+
response_processor.consume_all_responses_until_mn(entries.size)
|
|
443
453
|
end
|
|
444
454
|
raise value_error if value_error
|
|
445
455
|
end
|
|
@@ -451,7 +461,7 @@ module Dalli
|
|
|
451
461
|
**routing_token_kwargs(req_options))
|
|
452
462
|
flushed_write(buffer)
|
|
453
463
|
buffer.clear
|
|
454
|
-
keys.size - response_processor.pipelined_delete_non_deletions
|
|
464
|
+
keys.size - response_processor.pipelined_delete_non_deletions(keys.size)
|
|
455
465
|
end
|
|
456
466
|
|
|
457
467
|
require_relative 'key_regularizer'
|
|
@@ -26,6 +26,8 @@ module Dalli
|
|
|
26
26
|
VA_PREFIX = 'VA '
|
|
27
27
|
# memcached can't store an item larger than 1 GiB (its -I maximum)
|
|
28
28
|
MAX_VALUE_BYTES = 1024 * 1024 * 1024
|
|
29
|
+
MAX_STATS_ENTRIES = 10_000
|
|
30
|
+
MAX_QUIET_RESPONSES = 100_000
|
|
29
31
|
HD_PREFIX = 'HD '
|
|
30
32
|
FLAGS_TOKEN_PREFIX = ' f'
|
|
31
33
|
CAS_TOKEN_PREFIX = ' c'
|
|
@@ -35,6 +37,8 @@ module Dalli
|
|
|
35
37
|
BYTE_F = 'f'.ord
|
|
36
38
|
BYTE_K = 'k'.ord
|
|
37
39
|
BYTE_S = 's'.ord
|
|
40
|
+
BYTE_CR = "\r".ord
|
|
41
|
+
BYTE_LF = "\n".ord
|
|
38
42
|
|
|
39
43
|
T_OK = [OK].freeze
|
|
40
44
|
T_RESET = [RESET].freeze
|
|
@@ -174,7 +178,11 @@ module Dalli
|
|
|
174
178
|
def stats
|
|
175
179
|
tokens = error_on_unexpected!(T_END_TOKEN_STAT)
|
|
176
180
|
values = {}
|
|
181
|
+
replies = 0
|
|
177
182
|
while tokens.first != END_TOKEN
|
|
183
|
+
replies += 1
|
|
184
|
+
raise Dalli::DalliError, 'Too many stats replies' if replies > MAX_STATS_ENTRIES
|
|
185
|
+
|
|
178
186
|
values[tokens[1]] = tokens[2]
|
|
179
187
|
tokens = next_line_to_tokens
|
|
180
188
|
end
|
|
@@ -198,10 +206,16 @@ module Dalli
|
|
|
198
206
|
tokens.last
|
|
199
207
|
end
|
|
200
208
|
|
|
201
|
-
def consume_all_responses_until_mn
|
|
209
|
+
def consume_all_responses_until_mn(max_responses = MAX_QUIET_RESPONSES)
|
|
202
210
|
tokens = next_line_to_tokens
|
|
203
211
|
|
|
204
|
-
|
|
212
|
+
replies = 0
|
|
213
|
+
while tokens.first != MN
|
|
214
|
+
replies += 1
|
|
215
|
+
raise Dalli::DalliError, 'Too many quiet replies' if replies > max_responses
|
|
216
|
+
|
|
217
|
+
tokens = next_line_to_tokens
|
|
218
|
+
end
|
|
205
219
|
true
|
|
206
220
|
end
|
|
207
221
|
|
|
@@ -212,11 +226,13 @@ module Dalli
|
|
|
212
226
|
# was NOT deleted -- a miss (NF) or an error. Returns that count so
|
|
213
227
|
# callers can derive the number of successful deletes as
|
|
214
228
|
# (keys_sent - non_deletions).
|
|
215
|
-
def pipelined_delete_non_deletions
|
|
229
|
+
def pipelined_delete_non_deletions(max_responses = MAX_QUIET_RESPONSES)
|
|
216
230
|
non_deletions = 0
|
|
217
231
|
tokens = next_line_to_tokens
|
|
218
232
|
until tokens.first == MN
|
|
219
233
|
non_deletions += 1
|
|
234
|
+
raise Dalli::DalliError, 'Too many delete replies' if non_deletions > max_responses
|
|
235
|
+
|
|
220
236
|
tokens = next_line_to_tokens
|
|
221
237
|
end
|
|
222
238
|
non_deletions
|
|
@@ -237,6 +253,13 @@ module Dalli
|
|
|
237
253
|
def getk_response_from_buffer(buf, offset = 0, raw: false)
|
|
238
254
|
# Find the header terminator starting from offset
|
|
239
255
|
term_idx = buf.byteindex(TERMINATOR, offset)
|
|
256
|
+
max_line_bytes = ConnectionManager::MAX_LINE_BYTES
|
|
257
|
+
header_too_long = if term_idx
|
|
258
|
+
term_idx - offset + TERMINATOR.bytesize > max_line_bytes
|
|
259
|
+
else
|
|
260
|
+
buf.bytesize - offset >= max_line_bytes
|
|
261
|
+
end
|
|
262
|
+
raise Dalli::DalliError, "Reply line without CRLF in the first #{max_line_bytes} bytes" if header_too_long
|
|
240
263
|
return [0] unless term_idx
|
|
241
264
|
|
|
242
265
|
if buf.byteslice(offset, VA_PREFIX.bytesize) == VA_PREFIX
|
|
@@ -280,6 +303,9 @@ module Dalli
|
|
|
280
303
|
# a complete response, don't advance the buffer
|
|
281
304
|
return [0] unless buf.bytesize >= offset + resp_size
|
|
282
305
|
|
|
306
|
+
term = offset + header_len + body_len
|
|
307
|
+
raise_bad_value_terminator unless buf.getbyte(term) == BYTE_CR && buf.getbyte(term + 1) == BYTE_LF
|
|
308
|
+
|
|
283
309
|
# The full response is in our buffer, so parse it and return
|
|
284
310
|
# the values
|
|
285
311
|
body = buf.byteslice(offset + header_len, body_len)
|
|
@@ -320,6 +346,9 @@ module Dalli
|
|
|
320
346
|
resp_size = header_len + size + TERMINATOR.length
|
|
321
347
|
return [0] unless buf.bytesize >= offset + resp_size
|
|
322
348
|
|
|
349
|
+
term = offset + header_len + size
|
|
350
|
+
raise_bad_value_terminator unless buf.getbyte(term) == BYTE_CR && buf.getbyte(term + 1) == BYTE_LF
|
|
351
|
+
|
|
323
352
|
value = retrieve(buf.byteslice(offset + header_len, size), raw ? 0 : bitflags || 0, raw)
|
|
324
353
|
# Skipped like the token path does; see getk_response_from_buffer
|
|
325
354
|
return [false, resp_size] unless key
|
|
@@ -456,9 +485,19 @@ module Dalli
|
|
|
456
485
|
end
|
|
457
486
|
|
|
458
487
|
def check_value_size!(size)
|
|
459
|
-
|
|
488
|
+
limit = @value_marshaller.max_response_bytes
|
|
489
|
+
return if size >= 0 && size <= MAX_VALUE_BYTES && size <= limit # rubocop:disable Style/ComparableBetween
|
|
490
|
+
|
|
491
|
+
effective_limit = [MAX_VALUE_BYTES, limit].min
|
|
492
|
+
raise Dalli::DalliError, "Reply value size #{size} exceeds the #{effective_limit}-byte response limit"
|
|
493
|
+
end
|
|
494
|
+
|
|
495
|
+
def strip_value_terminator!(data)
|
|
496
|
+
data&.chomp!(TERMINATOR) || raise_bad_value_terminator
|
|
497
|
+
end
|
|
460
498
|
|
|
461
|
-
|
|
499
|
+
def raise_bad_value_terminator
|
|
500
|
+
raise Dalli::DalliError, "Reply value isn't followed by CRLF, so its size doesn't match the value"
|
|
462
501
|
end
|
|
463
502
|
|
|
464
503
|
def read_line
|
|
@@ -474,7 +513,7 @@ module Dalli
|
|
|
474
513
|
# Checked before the terminator is added: -1 or -2 would otherwise
|
|
475
514
|
# read 1 or 0 bytes and leave the connection out of step
|
|
476
515
|
check_value_size!(data_size)
|
|
477
|
-
@io_source.read(data_size + TERMINATOR.bytesize)
|
|
516
|
+
strip_value_terminator!(@io_source.read(data_size + TERMINATOR.bytesize))
|
|
478
517
|
end
|
|
479
518
|
end
|
|
480
519
|
end
|
|
@@ -15,12 +15,14 @@ module Dalli
|
|
|
15
15
|
value_max_bytes: 1024 * 1024
|
|
16
16
|
}.freeze
|
|
17
17
|
|
|
18
|
-
attr_reader :value_max_bytes
|
|
18
|
+
attr_reader :value_max_bytes, :max_response_bytes
|
|
19
19
|
|
|
20
20
|
def initialize(client_options)
|
|
21
21
|
@value_max_bytes = client_options.fetch(:value_max_bytes) do
|
|
22
22
|
DEFAULTS.fetch(:value_max_bytes)
|
|
23
23
|
end.to_i
|
|
24
|
+
@max_response_bytes = Integer(client_options.fetch(:max_response_bytes, @value_max_bytes))
|
|
25
|
+
raise ArgumentError, 'max_response_bytes must be positive' unless @max_response_bytes.positive?
|
|
24
26
|
end
|
|
25
27
|
|
|
26
28
|
def store(key, value, _options = nil)
|
|
@@ -47,6 +47,8 @@ module Dalli
|
|
|
47
47
|
@marshal_options =
|
|
48
48
|
DEFAULTS.merge(client_options.slice(*OPTIONS))
|
|
49
49
|
@marshal_options[:value_max_bytes] = @marshal_options[:value_max_bytes].to_i
|
|
50
|
+
@max_response_bytes = Integer(client_options.fetch(:max_response_bytes, value_max_bytes))
|
|
51
|
+
raise ArgumentError, 'max_response_bytes must be positive' unless @max_response_bytes.positive?
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
def store(key, value, options = nil)
|
|
@@ -67,6 +69,8 @@ module Dalli
|
|
|
67
69
|
@marshal_options[:value_max_bytes]
|
|
68
70
|
end
|
|
69
71
|
|
|
72
|
+
attr_reader :max_response_bytes
|
|
73
|
+
|
|
70
74
|
def error_if_over_max_value_bytes(key, value)
|
|
71
75
|
self.class.error_if_over_max_value_bytes(key, value, value_max_bytes)
|
|
72
76
|
end
|
data/lib/dalli/socket.rb
CHANGED
|
@@ -19,6 +19,10 @@ module Dalli
|
|
|
19
19
|
##
|
|
20
20
|
module InstanceMethods
|
|
21
21
|
READ_CHUNK_SIZE = 8196
|
|
22
|
+
# Give the response parser control between bounded socket reads. In
|
|
23
|
+
# particular, a peer continuously sending a header without CRLF must
|
|
24
|
+
# not keep this method appending forever.
|
|
25
|
+
MAX_AVAILABLE_BYTES = READ_CHUNK_SIZE * 8
|
|
22
26
|
|
|
23
27
|
# Reads whatever is available without blocking. A read that returns less
|
|
24
28
|
# than a full chunk means the socket was drained, so we stop there rather
|
|
@@ -26,7 +30,7 @@ module Dalli
|
|
|
26
30
|
# Callers keep waiting on IO.select for anything that arrives later.
|
|
27
31
|
def read_available(reusable_buffer = nil)
|
|
28
32
|
if reusable_buffer
|
|
29
|
-
value = read_nonblock(READ_CHUNK_SIZE, reusable_buffer, exception: false)
|
|
33
|
+
value = read_nonblock([READ_CHUNK_SIZE, MAX_AVAILABLE_BYTES].min, reusable_buffer, exception: false)
|
|
30
34
|
case value
|
|
31
35
|
when :wait_writable, :wait_readable
|
|
32
36
|
return reusable_buffer.clear
|
|
@@ -34,13 +38,15 @@ module Dalli
|
|
|
34
38
|
raise Errno::ECONNRESET, "Connection reset: #{logged_options.inspect}"
|
|
35
39
|
end
|
|
36
40
|
return value if drained_after?(value)
|
|
41
|
+
return value if value.bytesize >= MAX_AVAILABLE_BYTES
|
|
37
42
|
else
|
|
38
43
|
value = ''.b
|
|
39
44
|
end
|
|
40
45
|
|
|
41
46
|
buffer = ''.b
|
|
42
47
|
loop do
|
|
43
|
-
result = read_nonblock(READ_CHUNK_SIZE,
|
|
48
|
+
result = read_nonblock([READ_CHUNK_SIZE, MAX_AVAILABLE_BYTES - value.bytesize].min,
|
|
49
|
+
buffer, exception: false)
|
|
44
50
|
case result
|
|
45
51
|
when :wait_writable, :wait_readable
|
|
46
52
|
buffer.clear
|
|
@@ -50,6 +56,7 @@ module Dalli
|
|
|
50
56
|
else
|
|
51
57
|
value << result
|
|
52
58
|
return value if drained_after?(result)
|
|
59
|
+
return value if value.bytesize >= MAX_AVAILABLE_BYTES
|
|
53
60
|
end
|
|
54
61
|
end
|
|
55
62
|
end
|
|
@@ -114,13 +121,17 @@ module Dalli
|
|
|
114
121
|
# jruby-openssl can take the next record off the socket during a short
|
|
115
122
|
# read and hold it where neither pending nor IO.select sees it, so on
|
|
116
123
|
# JRuby a read continues until the socket would block.
|
|
124
|
+
def pending_data?
|
|
125
|
+
pending.positive? || (@rbuffer && !@rbuffer.empty?)
|
|
126
|
+
end
|
|
127
|
+
|
|
117
128
|
if RUBY_ENGINE == 'jruby'
|
|
118
129
|
def buffered_data?
|
|
119
130
|
true
|
|
120
131
|
end
|
|
121
132
|
else
|
|
122
133
|
def buffered_data?
|
|
123
|
-
|
|
134
|
+
pending_data?
|
|
124
135
|
end
|
|
125
136
|
end
|
|
126
137
|
|
|
@@ -157,7 +168,12 @@ module Dalli
|
|
|
157
168
|
sock.options = { host: host, port: port }.merge(options)
|
|
158
169
|
init_socket_options(sock, options)
|
|
159
170
|
|
|
160
|
-
|
|
171
|
+
if options[:ssl_context]
|
|
172
|
+
wrapping_ssl_socket(sock, host, options[:ssl_context],
|
|
173
|
+
options[:socket_timeout])
|
|
174
|
+
else
|
|
175
|
+
sock
|
|
176
|
+
end
|
|
161
177
|
end
|
|
162
178
|
end
|
|
163
179
|
|
|
@@ -248,13 +264,15 @@ module Dalli
|
|
|
248
264
|
|
|
249
265
|
# Closes the TCP socket if the handshake fails or times out, so a failed
|
|
250
266
|
# attempt doesn't hold a file descriptor until GC.
|
|
251
|
-
def self.wrapping_ssl_socket(tcp_socket, host, ssl_context)
|
|
267
|
+
def self.wrapping_ssl_socket(tcp_socket, host, ssl_context, timeout = nil)
|
|
252
268
|
warn_if_unverified(ssl_context)
|
|
253
269
|
connected = false
|
|
254
270
|
ssl_socket = Dalli::Socket::SSLSocket.new(tcp_socket, ssl_context)
|
|
255
271
|
ssl_socket.hostname = host
|
|
256
272
|
ssl_socket.sync_close = true
|
|
257
|
-
|
|
273
|
+
# The underlying TCP socket's IO#timeout= does not reliably bound
|
|
274
|
+
# OpenSSL's blocking handshake on Ruby 3.3.
|
|
275
|
+
Timeout.timeout(timeout) { ssl_socket.connect }
|
|
258
276
|
connected = true
|
|
259
277
|
ssl_socket
|
|
260
278
|
ensure
|
data/lib/dalli/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
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.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter M. Goldstein
|
|
8
8
|
- Mike Perham
|
|
9
|
+
autorequire:
|
|
9
10
|
bindir: bin
|
|
10
11
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
+
date: 2026-11-14 00:00:00.000000000 Z
|
|
12
13
|
dependencies:
|
|
13
14
|
- !ruby/object:Gem::Dependency
|
|
14
15
|
name: logger
|
|
@@ -75,6 +76,7 @@ metadata:
|
|
|
75
76
|
bug_tracker_uri: https://github.com/petergoldstein/dalli/issues
|
|
76
77
|
changelog_uri: https://github.com/petergoldstein/dalli/blob/main/CHANGELOG.md
|
|
77
78
|
rubygems_mfa_required: 'true'
|
|
79
|
+
post_install_message:
|
|
78
80
|
rdoc_options: []
|
|
79
81
|
require_paths:
|
|
80
82
|
- lib
|
|
@@ -89,7 +91,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
89
91
|
- !ruby/object:Gem::Version
|
|
90
92
|
version: '0'
|
|
91
93
|
requirements: []
|
|
92
|
-
rubygems_version:
|
|
94
|
+
rubygems_version: 3.5.22
|
|
95
|
+
signing_key:
|
|
93
96
|
specification_version: 4
|
|
94
97
|
summary: High performance memcached client for Ruby
|
|
95
98
|
test_files: []
|