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

infinite loop in threadedclient.py when server closes websocket #23

Closed
tweber opened this issue Feb 13, 2012 · 2 comments
Closed

infinite loop in threadedclient.py when server closes websocket #23

tweber opened this issue Feb 13, 2012 · 2 comments

Comments

@tweber
Copy link

tweber commented Feb 13, 2012

I am using geventclient.py which subclasses WebSocketClient in threadedclient.py. The client connects and waits for a message. If the server sends a message and immediately closes the websocket, the client goes into an infinite loop. It happens in threadedclient.py in the _receive() method. Basically, there is a socket recv() command which returns "" indicating that the server has closed. But the _receive() method does not close, and calls socket recv() again. Here is the first part of the function with my patch, which fixes the problem in my limited tests.

def _receive(self):
    next_size = 2
    try:
        self.sock.setblocking(1)
        while self.running:
            if self.__buffer:
                bytes, self.__buffer = self.__buffer[:next_size], self.__buffer[next_size:]
            else:
                bytes = self.read_from_connection(next_size)

            ######### patch start
            if bytes is None or len(bytes) == 0:
                self.server_terminated = True
                self.running = False
                break
            ######### patch end

            with self._lock:
                s = self.stream
                next_size = s.parser.send(bytes)
@Lawouach
Copy link
Owner

Hello there, I think you're running an older version of ws4py. Would you mind trying with the latest? I'll try to investigate on my side as well.

@Lawouach
Copy link
Owner

Lawouach commented Apr 9, 2012

This is indeed an old release of ws4py. I advise you to upgrade to the latest release. Thanks.

@Lawouach Lawouach closed this as completed Apr 9, 2012
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