5

I get a connection exception (given at the end) even though I did the following:

While creating an instance of Jedis, I set the timeout field to 1 hr (60*60*1000). I also tried it with 0, that doesn't work either.

When I checked the log after 7 mins, I noticed it, although I think the exception would have occurred much earlier (at 300 secs). Why do I keep getting it? Any idea why?

Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: It seems like server has closed the connection.
    at redis.clients.util.RedisInputStream.readLine(RedisInputStream.java:90)
    at redis.clients.jedis.Protocol.processMultiBulkReply(Protocol.java:111)
    at redis.clients.jedis.Protocol.process(Protocol.java:64)
    at redis.clients.jedis.Protocol.read(Protocol.java:127)
    at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:199)
    at redis.clients.jedis.BinaryJedis.smembers(BinaryJedis.java:1187)
SANN3
  • 9,459
  • 6
  • 61
  • 97
Alex
  • 1,406
  • 2
  • 18
  • 33
  • I have encountered this problem. Can you help me? thanks. [http://stackoverflow.com/questions/34131736/redis-it-seems-like-server-has-closed-the-connection](http://stackoverflow.com/questions/34131736/redis-it-seems-like-server-has-closed-the-connection) – jonnyLee Dec 09 '15 at 02:33

1 Answers1

3

I would suggest:

  • to check an inactivity timeout is not set in the Redis server configuration file. Set it to zero. https://github.com/antirez/redis/blob/unstable/redis.conf#L44

  • to check that the smembers commands executed by your application do not return millions of items. Past a certain threshold, large communication buffers can lead to connection closure.

Of course, it can also be due to the network infrastructure itself, especially if you run Redis client and server on distinct VMs of a public cloud.

Didier Spezia
  • 70,911
  • 12
  • 189
  • 154
  • I checke redis.conf file and found this line "timeout 0" do I need to change anything. Also I didnt understand your SMEMBER comment. Kindly elaborate. – Alex Oct 21 '13 at 09:23
  • Timeout 0 means no inactivity timeout - which is fine. Looking at the stack you posted, it seems it fails on a smembers command. So you may want to check if the set returned by this command is small or very large. – Didier Spezia Oct 21 '13 at 17:09
  • I was using jedis in multithreaded environment with Connection Pool. Now I created Connection Pool and used setTestOnBorrow(true) the problem seems to be solved for now. Lets see!!! Finger crossed!! – Alex Oct 22 '13 at 09:21