Bug 745822 (EDG-49)

Summary: malformed memcached cas command should result in CLIENT_ERROR
Product: [JBoss] JBoss Data Grid 5 Reporter: Michal Linhard <mlinhard>
Component: InfinispanAssignee: Default User <jbpapp-maint>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: high Docs Contact:
Priority: high    
Version: EAP 5.1.0 EDG TPCC: nobody
Target Milestone: ---   
Target Release: EAP 5.1.0 EDG TP   
Hardware: Unspecified   
OS: Unspecified   
URL: http://jira.jboss.org/jira/browse/EDG-49
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-11-17 17:33:33 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Michal Linhard 2010-11-15 15:27:43 UTC
project_key: EDG

When given following input:

[mlinhard@michal-linhard ~]$ echo -e "cas bad blah 0 0 0\r\n\r\n" | nc localhost 11211
SERVER_ERROR org.infinispan.server.core.ServerException: java.lang.NumberFormatException: For input string: "blah"
[mlinhard@michal-linhard ~]$ echo -e "cas bad 0 blah 0 0\r\n\r\n" | nc localhost 11211
SERVER_ERROR org.infinispan.server.core.ServerException: java.lang.NumberFormatException: For input string: "blah"
[mlinhard@michal-linhard ~]$ echo -e "cas bad 0 0 blah 0\r\n\r\n" | nc localhost 11211
SERVER_ERROR org.infinispan.server.core.ServerException: java.lang.NumberFormatException: For input string: "blah"
[mlinhard@michal-linhard ~]$ echo -e "cas bad 0 0 0 blah\r\n\r\n" | nc localhost 11211
SERVER_ERROR org.infinispan.server.core.ServerException: java.lang.NumberFormatException: For input string: "blah"

in each case memcached server module should have replied with "CLIENT_ERROR <error>\r\n"
as required in: https://github.com/memcached/memcached/blob/master/doc/protocol.txt

FYI: original memcached server implementation replies "CLIENT_ERROR bad command line format\r\n" (which is also expected by their test suite, but not required by protocol)

Comment 1 Michal Linhard 2010-11-15 15:40:22 UTC
and one more related thing:

missing cas value should result in CLIENT_ERROR instead SERVER_ERROR:
[mlinhard@michal-linhard ~]$ echo -e "cas foo 0 0 6 \r\nbarva2\r\n" | nc localhost 11211
SERVER_ERROR org.infinispan.server.core.ServerException: java.lang.ArrayIndexOutOfBoundsException: 3

but in this case I'm a bit uncertain because original memcached server replies ERROR here. to me this seems like a bug on their side, because the mentioned input "cas foo 0 0 6 \r\nbarva2\r\n" is not an unknown command (=ERROR) but " error in the input line, i.e. the input doesn't conform to the protocol in some way" (=CLIENT_ERROR)

Comment 2 Galder Zamarreño 2010-11-16 10:04:28 UTC
Thanks Michal. Wrt your last comment, one thing is for sure, it shouldn't throw an ArrayIndexOutOfBoundsException, so I'll go with a CLIENT_ERROR for that.

Comment 3 Galder Zamarreño 2010-11-16 10:05:43 UTC
Actually, I know why it sends an ERROR saying unknown command. That's cos after \r\n, a new command starts, and hence barva2 is not a known command. The server is right on this.

Comment 4 Galder Zamarreño 2010-11-16 10:10:24 UTC
Not sure actually. I'll double check what the server does with "cas foo 0 0 6 \r\nbarva2\r\n" to be more precise and get back to you.

Comment 5 Galder Zamarreño 2010-11-16 10:11:18 UTC
Link: Added: This issue depends ISPN-773


Comment 6 Galder Zamarreño 2010-11-16 17:06:28 UTC
It seems like Memcached server is just sending you the last of the errors, which indeed is an unknown command, but this is just a side effect of the first error, which is the lack of the cas id. I'm gonna go with CLIENT_ERROR cos, as you rightly pointed out, that's the real issue here.

Comment 7 Michal Linhard 2010-11-17 11:00:18 UTC
Yes, there's one ERROR for the "barva2\r\n" input as well, but it says error also to the first line (the original memcached implementation):

$ echo -e "cas foo 0 0 6 \r\nbarva2\r" | nc localhost 11212
ERROR
ERROR
$ echo -e "cas foo 0 0 6 \r" | nc localhost 11212
ERROR


Comment 8 Galder Zamarreño 2010-11-17 11:29:08 UTC
Oh right, it mentions both. I've coded it to show the first which is the key one as CLIENT_ERROR. I don't think we should get too hang up on this though.