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

AutoReconnect goes into an endless loop #31

Open
pr4gmat1q opened this issue Dec 15, 2018 · 5 comments
Open

AutoReconnect goes into an endless loop #31

pr4gmat1q opened this issue Dec 15, 2018 · 5 comments
Labels

Comments

@pr4gmat1q
Copy link

Hey. Faced a problem. When a session fails, it often does not work through reconnection. The try_reconnect method goes into an infinite loop and always throws a BrokenPipeError exception: [Errno 32] Broken pipe

client = AMIClient(address=config.ami_host, port=config.ami_port,timeout=2)
AutoReconnect(ami_client=client,delay=1)
future = client.login(username=config.ami_user,secret=config.ami_pass)


client.add_event_listener(
"""
add listeners
"""
)

if future.response.is_error():
 raise Exception(str(future.response))

try:
    while True:
        time.sleep(5)
except (KeyboardInterrupt, SystemExit):
 client.logoff()

@pr4gmat1q
Copy link
Author

After about how much to wait for a fix? Connection problem is very important.
Thank.

@pr4gmat1q
Copy link
Author

pr4gmat1q commented Jan 10, 2019

@ettoreleandrotognoli
my Workaround:
client.py
class AutoReconnect

    def try_reconnect(self):
        try:
            f = self._login(*self._login_args[0], **self._login_args[1])
            response = f.response
            if response is not None and not response.is_error():
                self.on_reconnect(self._ami_client, response)
                return True
        except (BrokenPipeError):
            self._ami_client._socket.close()
            self._ami_client._socket = None
            self._ami_client.connect()
            self.try_reconnect()
        except:
            pass
        return False

@pr4gmat1q
Copy link
Author

@ettoreleandrotognoli
my Workaround:
client.py
class AutoReconnect

    def try_reconnect(self):
        try:
            f = self._login(*self._login_args[0], **self._login_args[1])
            response = f.response
            if response is not None and not response.is_error():
                self.on_reconnect(self._ami_client, response)
                return True
        except (BrokenPipeError):
            self._ami_client._socket.close()
            self._ami_client._socket = None
            self._ami_client.connect()
            self.try_reconnect()
        except:
            pass
        return False

It working

        except (BrokenPipeError):
            self._ami_client.disconnect()
            self.try_reconnect()

@otahmasebi
Copy link

add self.daemon = True after line

self.finished = threading.Event()
and self.join() after
self.finished.wait(self.delay)

@daverck
Copy link

daverck commented Nov 3, 2021

In my case, adding self._ami_client.disconnect() in the run function did the trick:

    def run(self):
        self.finished.wait(self.delay)
        while not self.finished.is_set():
            if not self.ping():
                self._ami_client.disconnect()
                self.try_reconnect()
            self.finished.wait(self.delay)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants