question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random ConnectionErrors (104, Connection reset by peer)

See original GitHub issue

Version: redis-py: 3.2.1 redis server: 5.0.5

Platform: Debian

Description: I have a connection to the Server that is idle for a few hours, and when I try to perform an operation, I get a redis.exceptions.ConnectionError: Error while reading from socket: (104, 'Connection reset by peer'). This happens not always but often enough to be annoying. I can wrap it in a try-except and just reconnect and it will work, however i don’t want to wrap every command to redis like this.

Some Background: The program is getting tasks from a Queue implemented in Redis, computing for a few hours, getting the next task, and so on.

The question is, is this a bug or expected? Is there an option to prevent this? I don’t have any timeouts set on the client or server (everything is default). The current workaround would be to emulate a pre-ping, by sending a ping wrapped in a try-except-and-reconnect-if-needed, but it’s not very pretty.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:24
  • Comments:35 (11 by maintainers)

github_iconTop GitHub Comments

22reactions
andymccurdycommented, Aug 19, 2019

Hi, sorry I haven’t responded to this issue earlier. Upgrading to version 3.3.x should improve your experience. 3.3.x added a new option health_check_interval. You can use health checks like:

client = redis.Redis(..., health_check_interval=30)

The value of health_check_interval specifies the time in seconds a connection can be idle before its health needs to be checked. In the above case, if the connection is idle for more than 30 seconds, a round trip PING/PONG will be attempted just before your next command. If the PING/PONG fails, the connection will reestablished behind the scenes before your intended command is executed.

8reactions
ulodcivcommented, Sep 19, 2019

We are currently testing GCP MemoryStore as a replacement for memcache.

Using GAE Python 2.7, we get random “ConnectionError: Error while reading from socket: (104, ‘Connection reset by peer’)”. Typically this error occurs after about 120 seconds of waiting for some redis command to complete (delete, set, get), so they can be hard to handle with a backoff mechanism.

We use version 3.3.8. I’ve been testing using health_check_interval=30 and lower values than 30 (down to 2, currently). This seems to have made the errors less frequent, but they still occur often enough to be of concern.

Perhaps this is a purely MemoryStore/redis server issue, however.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What are the general rules for getting the 104 "Connection ...
A website is not "sending " a "Connection reset by peer" error. This error is generated by the OS kernel on the client...
Read more >
Fix & Solve Error 104 Connection Reset By Peer Code Issue
How to Fix Error 104 Connection Reset by Peer Windows Issue · 1. Clear your Internet Browser Cache & Cookies on your PC...
Read more >
Connection reset by peer (os error 104) : r/rust - Reddit
My issue is that I randomly get a "Connection reset by peer (os error 104)" error when refreshing the page and I am...
Read more >
How to Fix The "Connection reset by peer" SSH Error
The “ssh_exchange_identification: read: Connection reset by peer” error indicates that the remote machine abruptly closed the Transition Control ...
Read more >
104: Connection reset by peer while reading response header ...
In my case of same problem, I just restart the php-fpm service so it solved.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found