Posts Tagged ‘Redis’

Redis异常JedisConnectionException:Read timed out解决笔记

星期三, 六月 25th, 2014 0 views

笔记①

异常如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
    at redis.clients.jedis.Protocol.process(Protocol.java:131)
    at redis.clients.jedis.Protocol.read(Protocol.java:187)
    at redis.clients.jedis.Connection.getIntegerReply(Connection.java:200)
    at redis.clients.jedis.BinaryJedis.incrBy(BinaryJedis.java:633)
    at java.util.TimerThread.mainLoop(Unknown Source)
    at java.util.TimerThread.run(Unknown Source)
Caused by: java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109)
    at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45)
    at redis.clients.jedis.Protocol.process(Protocol.java:116)
    ... 8 more

在服务器运行中突发异常,当时对Redis的操作并不频繁,大概一分钟一次的写数据,初步分析排除了资源竞争照成的Redis超时异常。
之后ping -t 远程Redis主机,发现当出现Read timed out异常时经常伴有ping超时情况,初步判定为网络不稳定照成。

临时解决办法是在new JedisPool(config, host, port, timeout) 初始化时,将timeout设置成更大的值(默认是2000)以便应对极端网络情况下的读取流异常情况。更进一步的分析还有待发掘,本篇未完待续。