twitter / twemproxy

A fast, light-weight proxy for memcached and redis
Apache License 2.0
12.13k stars 2.06k forks source link

stray message on server connection if \0 in the key for memcache #221

Open allenlz opened 10 years ago

allenlz commented 10 years ago

Example: echo -en "set a\0 0 0 1\r\na\r\n"

\0 is invalid in the key for memcache. If \0 is included, memcache will return 'ERROR' before continue to read the data in the connection. It will cause twemproxy to find stray message. This case is much like #149 .

In most cases, client side should do the validation for the key. However, its also needed to check the key again in twemproxy. Because, if twemproxy find stray message, it will close the server connection. 'Doing so would affect other clients that have request pending/outstanding on this given server connection.'

The fix is simple. https://github.com/allenlz/twemproxy/commit/5fddf251919a402f30690651ff20439c3fbbf34d

manjuraj commented 9 years ago

@idning is this still a problem with support for empty keys?

idning commented 9 years ago

@manjuraj @allenlz this is not empty key but '\0' in the key. (redis support '\0' in the key but memcache ascii protocol does not)

I will merge this PR latter

TysonAndre commented 3 years ago

I'm able to reproduce that

In most cases, client side should do the validation for the key.

I see - so twemproxy should close the connection to the client if it sees \0 or \n in a key or argument (memcached handles \n differently from twemproxy, which looks for \r)