最近开发环境使用redisson(版本是2.8.0),在部署一段时间(半个小时左右),获取分布式锁会报超时异常(org.redisson.client.RedisTimeoutException: Redis server response timeout (3000 ms) occured for command):
2018-06-28 15:01:55.919 [http-nio-8081-exec-6] ERROR [com.skylink.fincredit.controller.JoinThirdController.getLock(JoinThirdController.java:169)] exception ..... org.redisson.client.RedisTimeoutException: Redis server response timeout (3000 ms) occured for command: (EVAL) with params: [if (redis.call('exists', KEYS[1]) == 0) then redis.call('hset', KEYS[1], ARGV[2], 1); redis.call('pe..., 1, sl.redis.locker.finance_acc_customer11000018_3333333333, 60000, 5b4c46fd-d283-49f0-bf98-d7f160df863e:37] channel: [id: 0xf02a572d, L:/192.168.15.126:54288 - R:/192.168.20.66:7301] at org.redisson.command.CommandAsyncService$11.run(CommandAsyncService.java:704) ~[redisson-3.6.5.jar:?] at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:663) ~[netty-common-4.1.22.Final.jar:4.1.22.Final] at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:738) ~[netty-common-4.1.22.Final.jar:4.1.22.Final] at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:466) ~[netty-common-4.1.22.Final.jar:4.1.22.Final] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_66] 2018-06-28 15:01:58 ERROR [com.skylink.common.locker.redisson.RedissonLocker.release(RedissonLocker.java:72)] Locker release(finance_acc_customer11000018_3333333333) throw Exception. org.redisson.client.RedisTimeoutException: Redis server response timeout (3000 ms) occured for command: (EVAL) with params: [if (redis.call('exists', KEYS[1]) == 0) then redis.call('publish', KEYS[2], ARGV[1]); return 1; end;..., 2, sl.redis.locker.finance_acc_customer11000018_3333333333, redisson_lock__channel:{sl.redis.locker.finance_acc_customer11000018_3333333333}, 0, 30000, 5b4c46fd-d283-49f0-bf98-d7f160df863e:37] channel: [id: 0x34dfe77f, L:/192.168.15.126:54281 - R:/192.168.20.66:7301] at org.redisson.command.CommandAsyncService$11.run(CommandAsyncService.java:704) at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:663) at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:738) at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:466) at java.lang.Thread.run(Thread.java:745) 2018-06-28 15:01:59.004 [http-nio-8081-exec-6] INFO [com.skylink.fincredit.logger.LoggingAspect.logAround(LoggingAspect.java:85)] Exit: com.skylink.fincredit.controller.JoinThirdController.getLock() with result = {retCode=SUCCESS, retMsg=操作成功 } 2018-06-28 15:02:14.098 [redisson-netty-1-8] ERROR [org.redisson.client.handler.CommandsQueue.exceptionCaught(CommandsQueue.java:139)] Exception occured. Channel: [id: 0xf02a572d, L:/192.168.15.126:54288 - R:/192.168.20.66:7301] java.io.IOException: 远程主机强迫关闭了一个现有的连接。
查看资料,该问题在2017年11月23号已经修复(参见:https://github.com/redisson/redisson/issues/946),更新ressdion到3.6.5,设置setPingConnectionInterval为60秒:
测试后问题还是没有解决,继续在GitHub上查看原代码,发现在3.6.5版本没有修改完全,存在bug,查看在18年4月27号修复了:
继续升级版本到3.7.3,测试问题已经解决。
在redisson升级的过程中,报如下错:
redisson验证uri的方式变了,在2.8.0中使用的是ip:port格式,在3.6.5中使用的是rediss://ip:port,需要添加前缀。
redis连接超时,只有在NAT网络环境才会出现。