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.
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.