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

Too many open files due to generator not closing connection. #32

Open
sciuridae0603 opened this issue Aug 18, 2021 · 2 comments
Open

Too many open files due to generator not closing connection. #32

sciuridae0603 opened this issue Aug 18, 2021 · 2 comments

Comments

@sciuridae0603
Copy link

I find a problem when the client opens a stream and the server doesn't push anything, it will cause connection to stuck and won't close, then too many open files error happened.

So I edit some code to send some dummy messages (like ping) to prevent that happen.

And here's my workaround :

        def generator():
            pubsub = self.redis.pubsub()
            pubsub.subscribe(channel)
            try:
                while True:
                    message = pubsub.get_message()
                    if message == None:
                        yield "event:ping\ndata:{}\n\n"
                        time.sleep(0.4)
                    elif message['type'] == 'message':
                        msg_dict = json.loads(message['data'])
                        yield str(Message(**msg_dict))
            except GeneratorExit:
                pass
            except:
                traceback.print_exc()
            finally:
                pubsub.unsubscribe(channel)
@sciuridae0603 sciuridae0603 changed the title Too many open files due to generator not closing Too many open files due to generator not closing connection. Aug 18, 2021
@faruqsandi
Copy link

Hi @sciuridae0603! It's already months since this issue, is there any problem after you fix this with your workaround? I face the same error.
image

@sciuridae0603
Copy link
Author

@faruqsandi I think my workaround won't cause any problem, except it will send a ping every 0.4 secs, which may cost more internet bandwidth.

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

2 participants