Incorrect result codes on operations after CAS for Binary Protocol

Bug #994772 reported by Mason Malone
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
libmemcached
Fix Released
Medium
Brian Aker

Bug Description

When MEMCACHED_BEHAVIOR_BINARY_PROTOCOL it enabled and memcached_cas() is called with a bad CAS, a subsquent memcached_set() will return a "CONNECTION DATA EXISTS" error. The attached program outputs the following on my machine (running libmemcached 1.0.7):

mmalone@mmalone-SN68S:~/packages/libmemcached-1.0.7/clients$ gcc -L/usr/local/lib -o reproduce_bug reproducebug.c -lmemcached && ./reproduce_bug
RESULT OF INITIAL SET = #0 SUCCESS
RESULT OF BAD CAS SET = #21 SERVER END
RESULT OF NEW SET = #12 CONNECTION DATA EXISTS

Disabling MEMCACHED_BEHAVIOR_BINARY_PROTOCOL fixes the issue.

Revision history for this message
Mason Malone (mmalone-h) wrote :
Revision history for this message
Mason Malone (mmalone-h) wrote :

I looked at what memcache is responding with and confirmed it's returning the right data, so this isn't a bug in memcache. Here's the output when I start memcached v1.4.13 with -vv and run reproduce_bug:

<35 new auto-negotiating client connection
35: Client using the ascii protocol
<35 quit
<35 connection closed.
<35 new auto-negotiating client connection
35: Client using the binary protocol
<35 Read binary protocol data:
<35 0x80 0x01 0x00 0x07
<35 0x08 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x12
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 SET testkey Value len is 3
>35 Writing bin response:
>35 0x81 0x01 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x09
<35 Read binary protocol data:
<35 0x80 0x0d 0x00 0x07
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x07
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 GET testkey
>35 Writing bin response:
>35 0x81 0x0d 0x00 0x07
>35 0x04 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x0e
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
<35 Read binary protocol data:
<35 0x80 0x0a 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
>35 Writing bin response:
>35 0x81 0x0a 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
<35 Read binary protocol data:
<35 0x80 0x03 0x00 0x07
<35 0x08 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x12
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x27 0x0f
<35 REPLACE testkey Value len is 3
CAS: failure: expected 9, got 9999
>35 Writing an error: Data exists for key.
>35 Writing bin response:
>35 0x81 0x03 0x00 0x00
>35 0x00 0x00 0x00 0x02
>35 0x00 0x00 0x00 0x14
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
<35 Read binary protocol data:
<35 0x80 0x01 0x00 0x09
<35 0x08 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x14
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 0x00 0x00 0x00 0x00
<35 SET different Value len is 3
>35 Writing bin response:
>35 0x81 0x01 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x00
>35 0x00 0x00 0x00 0x0a
<35 connection closed.

Brian Aker (brianaker)
Changed in libmemcached:
assignee: nobody → Brian Aker (brianaker)
importance: Undecided → Medium
summary: - Incorrect result codes on operations after CAS
+ Incorrect result codes on operations after CAS for Binary Protocol
Revision history for this message
Brian Aker (brianaker) wrote :

=== modified file 'tests/libmemcached-1.0/all_tests.h'
--- tests/libmemcached-1.0/all_tests.h 2012-05-11 04:19:35 +0000
+++ tests/libmemcached-1.0/all_tests.h 2012-05-11 07:09:16 +0000
@@ -274,6 +274,7 @@
   {"lp:490520", true, (test_callback_fn*)regression_bug_490520 },
   {"lp:854604", true, (test_callback_fn*)regression_bug_854604 },
   {"lp:996813", true, (test_callback_fn*)regression_996813_TEST },
+ {"lp:994772", true, (test_callback_fn*)regression_994772_TEST },
   {0, false, (test_callback_fn*)0}
 };

=== modified file 'tests/libmemcached-1.0/mem_functions.cc'
--- tests/libmemcached-1.0/mem_functions.cc 2012-05-11 04:19:35 +0000
+++ tests/libmemcached-1.0/mem_functions.cc 2012-05-11 07:09:16 +0000
@@ -4590,6 +4590,46 @@
 }

+test_return_t regression_994772_TEST(memcached_st* memc)
+{
+ test_skip(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1));
+
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_set(memc,
+ test_literal_param(__func__), // Key
+ test_literal_param(__func__), // Value
+ time_t(0), uint32_t(0)));
+
+ const char *keys[] = { __func__ };
+ size_t key_length[]= { strlen(__func__) };
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_mget(memc, keys, key_length, 1));
+
+ memcached_return_t rc;
+ memcached_result_st *results = memcached_fetch_result(memc, NULL, &rc);
+ test_true(results);
+ test_compare(MEMCACHED_SUCCESS, rc);
+
+ test_strcmp(__func__, memcached_result_value(results));
+ uint64_t cas_value= memcached_result_cas(results);
+ test_true(cas_value);
+
+ // Bad cas value, sanity check
+ test_true(cas_value != 9999);
+ test_compare(MEMCACHED_END,
+ memcached_cas(memc,
+ test_literal_param(__func__), // Key
+ test_literal_param(__FILE__), // Value
+ time_t(0), uint32_t(0), 9999));
+
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc,
+ "different", strlen("different"), // Key
+ test_literal_param(__FILE__), // Value
+ time_t(0), uint32_t(0)));
+
+ return TEST_SUCCESS;
+}
+
 test_return_t regression_bug_854604(memcached_st *)
 {
   char buffer[1024];

=== modified file 'tests/libmemcached-1.0/mem_functions.h'
--- tests/libmemcached-1.0/mem_functions.h 2012-05-11 04:19:35 +0000
+++ tests/libmemcached-1.0/mem_functions.h 2012-05-11 07:09:16 +0000
@@ -175,3 +175,4 @@
 test_return_t wrong_failure_counter_two_test(memcached_st *memc);
 test_return_t kill_HUP_TEST(memcached_st *memc);
 test_return_t regression_996813_TEST(memcached_st*);
+test_return_t regression_994772_TEST(memcached_st*);

Revision history for this message
Brian Aker (brianaker) wrote :

Any update?

Changed in libmemcached:
milestone: none → 1.0.8
status: New → Fix Committed
Brian Aker (brianaker)
Changed in libmemcached:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.