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

jedis+spring get connection from pool failed #179

Closed
idodo opened this issue Jul 13, 2011 · 7 comments
Closed

jedis+spring get connection from pool failed #179

idodo opened this issue Jul 13, 2011 · 7 comments
Milestone

Comments

@idodo
Copy link

idodo commented Jul 13, 2011

Now i am using jedis2.0+ spring3, the config is like below:

 <!-- redis template definition -->
 <bean id="redisTemplate" class="org.springframework.data.keyvalue.redis.core.RedisTemplate"
    p:connection-factory-ref="jedisConnectionFactory"/>

 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxActive"  value="200" />
    <property name="maxIdle" value="50" />
    <property name="maxWait" value="3000" />
    <property name="testOnBorrow" value="true" />
</bean>

but sometimes it throw out exception below:
org.springframework.dao.DataAccessResourceFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:101)
at org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:148)
at org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:41)
at org.springframework.data.keyvalue.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:82)
at org.springframework.data.keyvalue.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:54)
at org.springframework.data.keyvalue.redis.core.RedisTemplate.execute(RedisTemplate.java:168)
at org.springframework.data.keyvalue.redis.core.RedisTemplate.execute(RedisTemplate.java:150)
at org.springframework.data.keyvalue.redis.core.AbstractOperations.execute(AbstractOperations.java:72)
at org.springframework.data.keyvalue.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:181)
at flighttycoon.db.redis.RedisProxy.set(RedisProxy.java:24)
at flighttycoon.service.AirlineService.updateFlight(AirlineService.java:589)
at flighttycoon.service.AirlineService.arriveAirline(AirlineService.java:340)
at flighttycoon.service.AirlineService$$FastClassByCGLIB$$e09872fe.invoke()
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:688)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621)
at flighttycoon.service.AirlineService$$EnhancerByCGLIB$$109bbd7a.arriveAirline()
at flighttycoon.controller.ApiController.airline(ApiController.java:312)
at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:571)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:640)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at flighttycoon.filter.MsgChecksumFilter.doFilter(MsgChecksumFilter.java:65)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:554)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:22)
at org.springframework.data.keyvalue.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:94)
... 52 more
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: connect timed out
at redis.clients.jedis.Connection.connect(Connection.java:124)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:54)
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1657)
at redis.clients.jedis.JedisPool$JedisFactory.makeObject(JedisPool.java:63)
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1181)
at redis.clients.util.Pool.getResource(Pool.java:20)

@costin
Copy link

costin commented Jul 13, 2011

You are missing the jedisConnectionFactory definition - are you wiring jedisPoolConfig into it?
You could increase the number of connections since it might be that the pool is too small.

@idodo
Copy link
Author

idodo commented Jul 14, 2011

Yes, i have the jedisConnectionFactory defination:

 <!-- redis template definition -->
 <bean id="redisTemplate" class="org.springframework.data.keyvalue.redis.core.RedisTemplate"
    p:connection-factory-ref="jedisConnectionFactory"/>

 <bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
    <property name="maxActive"  value="200" />
    <property name="maxIdle" value="50" />
    <property name="maxWait" value="3000" />
    <property name="testOnBorrow" value="true" />
</bean>

<bean id="redisProxy" class="flighttycoon.db.redis.RedisProxy">
    <property name="enable" value="true" />
</bean>

when the client reported the exception, i use the netstat show the established connection between redis, it showed that there were 30 connections, it was less than 200 (which i've set the maxActive for pool).

@costin
Copy link

costin commented Jul 22, 2011

I started having the same issues - seems that under load (when a lot of connections are opened and closed) the same problem occurs. I don't recall having that with Jedis 1.5.x - not sure what's happening but it seems that for whatever reason commons-pool cannot find/open a new connection and throws the exception.

@idodo
Copy link
Author

idodo commented Jul 22, 2011

you mean using jedis 1.5.x, there is no such problem? Now the problem indeedly occurs when i use jedis 2.0.

@xetorthio
Copy link
Contributor

can you please attach some code to reproduce this?

@xetorthio
Copy link
Contributor

It has been a while since this. And no more information was attached. I'm closing this issue.

@wishma2013
Copy link

I've meet the same exception in today morning ,but that's only because the password changed by my workmate and he didn't tell me.so I use the wrong password...

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

4 participants