xetorthio/jedis — pull request #468 by HeartSaVioR (2013-10-16 10:52:51+00:00)
Title: Fix unexpected behavior when Redis suddenly disconnect client

I have found this bug with #467 . (Thanks @AlexKorostov)

I have fixed a bug when Redis suddenly disconnect client.
Redis suddenly disconnect connection when subscriber is too slow to receive message, and buffer for subscriber grow too large.

> http://redis.io/topics/clients
> Output buffers limits
> Redis needs to handle a variable-length output buffer for every client, since a command can produce a big amount of data that needs to be transfered to the client.
> However it is possible that a client sends more commands producing more output to serve at a faster rate at which Redis can send the existing output to the client. This is especially true with Pub/Sub clients in case a client is not able to process new messages fast enough.
> Both the conditions will cause the client output buffer to grow and consume more and more memory. For this reason by default Redis sets limits to the output buffer size for different kind of clients. When the limit is reached the client connection is closed and the event logged in the Redis log file.

Fail scenario, and my approach explained at https://github.com/xetorthio/jedis/issues/467#issuecomment-26407662

Below is commit log

====

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