一、异常描述
通过客户端jedis连接redis服务器报出“..Caused by: java.net.SocketException: Software caused connection abort: recv failed..redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: recv failed..”
redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Software caused connection abort: recv failed[xwood-pms-publish] [pool-2-thread-11] 2017-06-04 16:47:59,356 - com.xwood.publish@b@er.master.PublishEntityDataHandler -1141351 [pool-2-thread-11] ERRORcom.xwood.publisher.master.PublishEntityDataHandler - 【extract - PublishEntityDataHandler:1】 s1-1@ err @ folderId:null @contentId: null@b@@b@ at redis.clients.jedis.Protocol.process(Protocol.java:146)@b@ at redis.clients.jedis.Protocol.read(Protocol.java:202)@b@ at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:285)@b@ at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:184)@b@ at redis.clients.jedis.Jedis.set(Jedis.java:63)@b@ at com.xwood.publisher.util.JedisUtil.set(JedisUtil.java:30)@b@ at com.xwood.publisher.master.PublishEntityDataHandler.pushRemoteRedis(PublishEntityDataHandler.java:43)@b@ at com.xwood.publisher.master.PublishEntityDataHandler.run(PublishEntityDataHandler.java:36)@b@ at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)@b@ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)@b@ at java.util.concurrent.FutureTask.run(FutureTask.java:138)@b@ at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)@b@ at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)@b@ at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)@b@ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)@b@ at java.lang.Thread.run(Thread.java:662)@b@Caused by: java.net.SocketException: Software caused connection abort: recv failed@b@ at java.net.SocketInputStream.socketRead0(Native Method)@b@ at java.net.SocketInputStream.read(SocketInputStream.java:147)@b@ at java.net.SocketInputStream.read(SocketInputStream.java:90)@b@ at redis.clients.util.RedisInputStream.fill(RedisInputStream.java:109)@b@ at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:45)
二、解决办法
如日志上下文通过jedis将空对象NULL键值存储到redis服务器造成无法存储,接受失败异常,原来相关代码如下
public static void set(String key,String value){@b@ @b@ JedisUtil.getclient().set(key, value);@b@ JedisUtil.getclient().save();//持久化@b@ @b@}
改为如下
public static void set(String key,String value){@b@ try{@b@ if(value!=null&&!"".equals(value)&&key!=null&&!"".equals(key)){@b@ JedisUtil.getclient().set(key, value);@b@ JedisUtil.getclient().save();//持久化@b@ }else{@b@ logger.error(" 【JedisUtil save NULL】 key-value:"+key+"@value:"+value);@b@ }@b@ @b@ }catch(JedisConnectionException e){@b@ e.printStackTrace();@b@ logger.error(" 【JedisUtil save exception】 key:"+key+"@value:"+key);@b@ }@b@}