Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cannot read response data included terminator when use meta protocol #1007

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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