fix bug in Protocol.processBulkReply()

* if RedisInputStream().read() at Protocol.processBulkReply() returns
-1, it runs with unexpected behavior
* fix: check and if return value is -1, it throws
JedisConnectionException with message "server has closed the connection"
** prevent unexpected behavior, specially ArrayIndexOutOfBoundException 
*** calls System.arraycopy() with length = -1 (cause limit = -1) at
RedisInputStream.read()

add pubsub unit test scenario : client-output-buffer-limit exceed

* Redis warns event(disconnect client) to their log, and suddenly
disconnected connection
** http://redis.io/topics/clients -> Output buffers limits
** so test expects JedisConnectionException with proper message
This commit is contained in:
임정택
2013-10-16 18:22:04 +09:00
parent 597366343d
commit e9506298f8
3 changed files with 76 additions and 1 deletions

View File

@@ -101,7 +101,10 @@ public final class Protocol {
int offset = 0;
try {
while (offset < len) {
offset += is.read(read, offset, (len - offset));
int size = is.read(read, offset, (len - offset));
if (size == -1)
throw new JedisConnectionException("It seems like server has closed the connection.");
offset += size;
}
// read 2 more bytes for the command delimiter
is.readByte();