Skip to content

Commit

Permalink
Fix to read response data using size when meta (petergoldstein#1007)
Browse files Browse the repository at this point in the history
  • Loading branch information
matsubara0507 authored Sep 16, 2024
1 parent f2a46a7 commit 06be66d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Dalli Changelog
Unreleased
==========

- Fix cannot read response data included terminator `\r\n` when use meta protocol (matsubara0507)

3.2.8
==========

Expand Down
8 changes: 6 additions & 2 deletions lib/dalli/protocol/meta/response_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def meta_get_with_value(cache_nils: false)
return cache_nils ? ::Dalli::NOT_FOUND : nil if tokens.first == EN
return true unless tokens.first == VA

@value_marshaller.retrieve(read_line, bitflags_from_tokens(tokens))
@value_marshaller.retrieve(read_data(tokens[1].to_i), bitflags_from_tokens(tokens))
end

def meta_get_with_value_and_cas
Expand All @@ -42,7 +42,7 @@ def meta_get_with_value_and_cas
cas = cas_from_tokens(tokens)
return [nil, cas] unless tokens.first == VA

[@value_marshaller.retrieve(read_line, bitflags_from_tokens(tokens)), cas]
[@value_marshaller.retrieve(read_data(tokens[1].to_i), bitflags_from_tokens(tokens)), cas]
end

def meta_get_without_value
Expand Down Expand Up @@ -205,6 +205,10 @@ def next_line_to_tokens
line = read_line
line&.split || []
end

def read_data(data_size)
@io_source.read(data_size + TERMINATOR.bytesize)&.chomp!(TERMINATOR)
end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions test/integration/test_operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@
end
end

it 'return the value that include TERMINATOR on a hit' do
memcached_persistent(p) do |dc|
dc.flush

val1 = "12345#{Dalli::Protocol::Meta::TERMINATOR}67890"
dc.set('a', val1)
val2 = dc.get('a')

assert_equal val1, val2

assert op_addset_succeeds(dc.set('a', nil))
assert_nil dc.get('a')
end
end

it 'returns nil on a miss' do
memcached_persistent(p) do |dc|
assert_nil dc.get('notexist')
Expand Down

0 comments on commit 06be66d

Please sign in to comment.