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

blpop will not receive any data if the key empty for a long time and then pushed a data #1199

Closed
kingname opened this issue Aug 5, 2019 · 6 comments

Comments

@kingname
Copy link

kingname commented Aug 5, 2019

Version: What redis-py and what redis version is the issue happening on?

  • redis-py: 3.2.1
  • redis: 5.0

Platform: What platform / version? (For example Python 3.5.1 on Windows 7 / Ubuntu 15.10 / Azure)

  • Ubuntu 18.04
  • Python 3.7.3

Description: Description of your issue, stack traces from errors and code that reproduces the issue

while True:
    data = client.blpop('key')[1]
    print(data)

this code will work normally when I launch it just now. but if the list keeps empty for a long time, for example, 2 days, and then I push a data to it. this code will still blocked at data = client.blpop('key')[1],could not receive any data. only after I terminal the process and relaunch it again, it can receive the new data.

@andymccurdy
Copy link
Contributor

Sounds like something on your network is killing the idle connection. And unfortunately the health check improvements in 3.3.x won't work in this case because we cannot send a health check in the middle of a blocking statement.

However you could pass a timeout to BRPOP. You'd just need to account for BRPOP returning None in the case the code hits the timeout.

@kingname
Copy link
Author

kingname commented Aug 5, 2019

Thanks for your reply.

So, if I pass a timeout, such as 5 minutes, and then, if I receive the data in 5 minutes, I parse it. if I don't, I parse the timeout logic, and then blpop again.

@kingname kingname closed this as completed Aug 5, 2019
@andymccurdy
Copy link
Contributor

If you call data = client.blpop('key', timeout=300), the code will block until either a value is pushed on to the key list or 300 seconds passes. If 300 seconds pass, None will be returned.

@captainst
Copy link

Got similar issue. I am using redis-py to get the keys from a remote redis server (over internet). I am using the code like:

while True:
    queue = db.blpop('detection_queue', timeout=5)
    if queue is not None:
        # process the queue

If the queue is empty, activity idle, without the timeout param, the process becomes dead (db.blpop never returned) after about 20 minutes.
Adding the timeout=5 seems to help quite a bit, but I still observed that the process is dead after about 9~10 hours of idle.

@andymccurdy
Copy link
Contributor

@captainst this seems like a separate issue. If you want to open another issue with details including your redis-py version and connection string I can take a look.

@captainst
Copy link

@andymccurdy Thank you for the fast reply. I'll do it.

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

3 participants