Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe #848

Closed
gauravparmar85 opened this issue Jan 9, 2015 · 13 comments

Comments

@gauravparmar85
Copy link

Hi I am using Jedis 2.4.2 and i am getting this exception almost every time I make a call.
I am initializing jedis pool as
JedisPool jedisPool = new JedisPool(config, uri.getHost(), uri.getPort(), 10000);

and trying to get keys using

public Set keySet(String pattern) {
boolean valid = true;
Jedis jedis = jedisPool.getResource();
try {
auth(jedis);
return jedis.keys(defaultKeyPrefix + pattern);
} catch (JedisException e) {
valid = false;
logger.warn("Redis read exception", e);
} finally {
if (valid) {
jedisPool.returnResource(jedis);
} else {
jedisPool.returnBrokenResource(jedis);
}
}
return null;
}

redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Broken pipe
at redis.clients.jedis.Connection.flush(Connection.java:70)
at redis.clients.jedis.Connection.getBinaryMultiBulkReply(Connection.java:210)
at redis.clients.jedis.Jedis.keys(Jedis.java:186)
..few more
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:111)
at org.quartz.core.JobRunShell.run(JobRunShell.java:223)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549)
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at redis.clients.util.RedisOutputStream.flushBuffer(RedisOutputStream.java:31)
at redis.clients.util.RedisOutputStream.flush(RedisOutputStream.java:223)
at redis.clients.jedis.Connection.flush(Connection.java:68)
... 10 more

@nykolaslima
Copy link
Contributor

@gauravparmar85 I think this problem was fixed by PR #651 and reported by issue #636

Can you upgrade to version 2.5.1 and test again?

@HeartSaVioR
Copy link
Contributor

@nykolaslima Unfortunately, it seems to not related to issue/PR you stated. It was ArrayIndexOutOfRangeException.
@gauravparmar85
Do you have any timeout configuration from Redis? Seems like Redis suddenly disconnected.
Could you share your Pool Config?
We can validate Jedis instance before getting it from pool, by GenericObjectPoolConfig.setTestOnBorrow(true);

@gauravparmar85
Copy link
Author

@HeartSaVioR Actually the scenario is, I have this job configured using spring cron and it runs once in 24 hours to create some report from the data that i keep in redis DB. I works fine for the first time when i create the JedisPool but starts failing after that.
JedisPool jedisPool = new JedisPool(config, uri.getHost(), uri.getPort(), 10000);
in the above initialization config is : config = new GenericObjectPoolConfig();

@gauravparmar85
Copy link
Author

Thanks all for your help. Modifying the pool config fixed this issue.

@hiakashjain
Copy link

@gauravparmar85 I am getting the same error, Can you please help me what exactly you changed/added in pool config to fix this problem.

@remy1991
Copy link

remy1991 commented Oct 8, 2015

@gauravparmar85 : Hey, can you share the changes done in the pool config. I am facing the same error.

@liuxuan207
Copy link

@gauravparmar85 , guy, could you share the pool config fixed the issue? I have the same problem.

@elvis9xu
Copy link

I encountered the same error, my code is as follows, and I use jdk 1.8
try (Jedis jedis = jedisPool.getResource()) {
byte[] bytes = jedis.get(key.toString().getBytes(defaultCharset));
}

There is a guy said change the redis config can solve this problem. Can any one find out which config to change?

@marcosnils
Copy link
Contributor

@elvis9xu he said that a pool config solved the issue, not a redis config. Maybe @gauravparmar85 can provide further info.

@zackypick
Copy link

Just had a similar issue and setting the test on borrow to true did the trick. I have a hunch that's what gauravparmar85 meant when he wrote "Thanks all for your help. Modifying the pool config fixed this issue" and vanished forever LOL :)

poolConfig.setTestOnBorrow(true);

@jamesone
Copy link

I just restarted my server which was using jedis, that fixed it for me.

@anjieych
Copy link

anjieych commented Mar 1, 2017

yeah,I do restart my app which is useing jedis, and it fixed.

bobbyguo added a commit to binarywang/WxJava that referenced this issue Apr 28, 2017
建议生产环境都使用带poolConfig的构造方法,防止redis出现链接异常,可参考 bug
redis/jedis#848
@phannghia1910
Copy link

The issue cause by your connection was out at the moment, you need to connect again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests