alphazero / jredis

Java Client and Connectors for Redis
http://code.google.com/p/jredis/
Apache License 2.0
315 stars 136 forks source link

Occasional exception: org.jredis.connector.ConnectionReset: Connection re-established but last request not processed: in.read returned -1 #57

Closed subwiz closed 12 years ago

subwiz commented 12 years ago

This is the trace:

[11-09-16 18:56:25.016] {http://*:8080-18} org.jredis.connector.ConnectionReset: Connection re-established but last request not processed:  in.read returned -1
                                                at org.jredis.ri.alphazero.connection.SyncConnection.serviceRequest(SyncConnection.java:138)
                                                at org.jredis.ri.alphazero.JRedisClient.serviceRequest(JRedisClient.java:151)
                                                at org.jredis.ri.alphazero.JRedisSupport.lrange(JRedisSupport.java:1218)
                                                at in.fileit.fileitin.OpPost.getKeyPosts(OpPost.java:360)
                                                at in.fileit.fileitin.OpPost.getPosts(OpPost.java:408)
                                                at in.fileit.fileitin.ServletIndex.doGet(ServletIndex.java:26)
                                                at javax.servlet.http.HttpServlet.service(HttpServlet.java:119)
                                                at javax.servlet.http.HttpServlet.service(HttpServlet.java:96)
                                                at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:109)
                                                at in.fileit.fileitin.FilterDataSource.doFilter(FilterDataSource.java:58)
                                                at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:89)
                                                at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:156)
                                                at com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
                                                at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:287)
                                                at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:811)
                                                at com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1186)
                                                at com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1148)
                                                at com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1132)
                                                at com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1055)
                                                at com.caucho.network.listen.TcpSocketLink.handleAcceptTask(TcpSocketLink.java:903)
                                                at com.caucho.network.listen.AcceptTask.doTask(AcceptTask.java:74)
                                                at com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:97)
                                                at com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:80)
                                                at com.caucho.network.listen.AcceptTask.run(AcceptTask.java:59)
                                                at com.caucho.env.thread.ResinThread.runTasks(ResinThread.java:164)
                                                at com.caucho.env.thread.ResinThread.run(ResinThread.java:130)

This is happening on random basis. I am using the latest jredis from trunk ( https://github.com/alphazero/jredis/commit/2c58286959a65617f71dbbb9d8d155c6722aab59 ) and using Redis 2.2.12.

alphazero commented 12 years ago

That's due to a connection timeout. Java does not raise an error on a dropped connection on send and it's only on the read end that you get a -1 returned (with semantics as defined in the javadocs e.g. "connection reset"). What is the timeout value in redis conf?

subwiz commented 12 years ago

It is set at 300 seconds in redis.conf.

This could also be due to the way I implemented Connection management---using ThreadLocal. So I will verify if there are any connections open in my side for more than 300 seconds.

Thanks for the pointer.

alphazero commented 12 years ago

NP; happy to help. I assumed you were pooling connections; can you confirm?

subwiz commented 12 years ago

I was believing that I have to manually pool connections..., so I implemented my logic based on a Servlet Filter which creates a new Redis connection, and throughout this particular request flow, this connection is used. Is there a better approach for pooling connections?

alphazero commented 12 years ago

hmm. If you have a connection per request, then why would it even be idle for > 300s ??

subwiz commented 12 years ago

I have to run some test if my implementation of ThreadLocal is holding connections open. So do you know of any OpenSource connection pool library for JRedis?

subwiz commented 12 years ago

I added few logs to my application and see that it is indeed timeout problem. Now I have pointer to work on this issue independently. I am closing this issue because this is not a JRedis bug.

Thanks a lot for the pointer.

alphazero commented 12 years ago

Reopening as documentation issue.

alphazero commented 12 years ago

Closing this. The javadoc for the exception states explicitly this is "typically due to timeout on Redis side".

subwiz commented 12 years ago

Can this also be added as part of Exception message?