NutzCN Logo
问答 Redis长时间连接后自动断开
发布于 567天前 作者 lihongjie0209 3205 次浏览 复制 上一个帖子 下一个帖子
标签:

代码逻辑为:

while(true){
redisService.brpop(0, key);

// business logic
}

错误信息: java.net.SocketException: Connection reset

5 回复

我查过文档, Redis server默认情况下是不会主动断开 Client 连接的, 所以很奇怪, 难道是Client这边的socket被操作系统关了? 开发环境是windows10.

多长时间?

从日志看2小时

[DEBUG] 22:02:48.206 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'emailAlertService'<class cn.boolin.service.alert.EmailAlertService>
enter exit to terminate: [INFO ] 22:02:48.206 cn.boolin.service.alert.EmailAlertService.run(EmailAlertService.java:52) - send email
[INFO ] 22:02:51.890 cn.boolin.service.alert.EmailAlertService.run(EmailAlertService.java:52) - send email
[ERROR] 00:02:54.814 cn.boolin.service.alert.ExceptionInterceptor.filter(ExceptionInterceptor.java:30) - java.net.SocketException: Connection reset
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Connection reset
	at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202)
	at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40)
	at redis.clients.jedis.Protocol.process(Protocol.java:151)
	at redis.clients.jedis.Protocol.read(Protocol.java:215)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
	at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:276)
	at redis.clients.jedis.Connection.getMultiBulkReply(Connection.java:269)
	at redis.clients.jedis.Jedis.brpop(Jedis.java:1768)
	at redis.clients.jedis.Jedis.brpop(Jedis.java:3452)
	at org.nutz.integration.jedis.RedisService.brpop(RedisService.java:6103)
	at org.nutz.integration.jedis.RedisService$$NUTZAOP._aop_invoke(RedisService.java:71)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at org.nutz.integration.jedis.RedisInterceptor.filter(RedisInterceptor.java:24)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at org.nutz.integration.jedis.RedisService$$NUTZAOP.brpop(RedisService.java:1)
	at cn.boolin.service.default_.DefaultReceiver.get(DefaultReceiver.java:34)
	at cn.boolin.service.default_.DefaultService.run(DefaultService.java:27)
	at cn.boolin.service.personal.PersonalService$$NUTZAOP._aop_invoke(PersonalService.java:1)
	at org.nutz.aop.InterceptorChain.invoke(InterceptorChain.java:77)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:57)
	at cn.boolin.service.alert.ExceptionInterceptor.filter(ExceptionInterceptor.java:28)
	at org.nutz.aop.InterceptorChain.doChain(InterceptorChain.java:60)
	at cn.boolin.service.personal.PersonalService$$NUTZAOP.run(PersonalService.java:1)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:210)
	at java.net.SocketInputStream.read(SocketInputStream.java:141)
	at java.net.SocketInputStream.read(SocketInputStream.java:127)
	at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196)
	... 28 more

哦,不晓得了,不过我建议用pub/sub吧

好的, 谢谢 @wendal

添加回复
请先登陆
回到顶部