Thursday December 04, 2008
Alignment bug in the binary protocol
When we implemented support for the binary protocol in the server we assigned the protocol header to a struct with the following code snippet:
protocol_binary_request_header* req; req = (protocol_binary_request_header*)c->rcurr; c->binary_header = *req;
The problem is that some hardware require a certain alignment for various datatypes, and SPARC is one of them. If you don't pipeline commands c->rcurr points to the beginning of a buffer allocated with malloc(), and malloc() will always return pointers to properly aligned memory. The problem occurs if you pipeline multiple commands to the server, and the size of one of them isn't a multiple of the structure alignment ( size % 8 != 0 ). I discovered this bug the other day when I experimented with the Spy memcached client by Dustin Sallings.
Luckily the bug was pretty easy to track down and fix: http://github.com/trondn/memcached/commit/4c3797b1d4fe9088ef96c9f7d571b1221cb40fef
Now I just need to figure out how to write a Perl test for the fix :)
Posted at 02:55PM Dec 04, 2008 by trond in Memcached | Comments[0]
| « December 2008 » | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
2 | 3 | 5 | 6 | |||
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 18 | 19 | 20 | |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | |||
| Today | ||||||