Skip to content

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

Open
@sciuridae0603

Description

@sciuridae0603

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions