-
Notifications
You must be signed in to change notification settings - Fork 859
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
Fixed TBClient reconnecting #1337
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -576,26 +576,40 @@ def _handle_remote_logging_level_update(self, config): | |
|
||
# HANDLERS SUPPORT METHODS ----------------------------------------------------------------------------------------- | ||
def _apply_connection_config(self, config) -> bool: | ||
apply_start = time() * 1000 | ||
old_tb_client = self._gateway.tb_client | ||
old_tb_client_config_path = self._gateway.tb_client.get_config_folder_path() | ||
old_tb_client_config = self._gateway.tb_client.config | ||
connection_logger = getLogger('tb_connection') | ||
try: | ||
old_tb_client.disconnect() | ||
self._gateway.tb_client.disconnect() | ||
self._gateway.tb_client.stop() | ||
|
||
connection_logger = getLogger('tb_connection') | ||
new_tb_client = TBClient(config, old_tb_client.get_config_folder_path(), connection_logger) | ||
while self._gateway.tb_client.client.is_connected(): | ||
sleep(1) | ||
|
||
apply_start = time() | ||
|
||
connection_state = False | ||
use_new_config = True | ||
while not connection_state: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add check for gateway status - is it stopped or no. |
||
for client in (new_tb_client, old_tb_client): | ||
client.connect() | ||
while time() * 1000 - apply_start >= 1000 and not connection_state: | ||
connection_state = client.is_connected() | ||
sleep(.1) | ||
|
||
if connection_state: | ||
self._gateway.tb_client = client | ||
self._gateway.subscribe_to_required_topics() | ||
return True | ||
self._gateway.__subscribed_to_rpc_topics = False | ||
new_tb_client = TBClient(config if use_new_config else old_tb_client_config, old_tb_client_config_path, connection_logger) | ||
new_tb_client.connect() | ||
while time() - apply_start <= 30 and not connection_state: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check is gateway running will be nice here as well. |
||
connection_state = new_tb_client.is_connected() | ||
sleep(.1) | ||
|
||
if connection_state: | ||
self._gateway.tb_client = new_tb_client | ||
self._gateway.__subscribed_to_rpc_topics = False | ||
self._gateway.subscribe_to_required_topics() | ||
return True | ||
else: | ||
new_tb_client.disconnect() | ||
new_tb_client.stop() | ||
while new_tb_client.client.is_connected(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a check is gateway running or stopped. |
||
sleep(1) | ||
apply_start = time() * 1000 | ||
use_new_config = not use_new_config | ||
except Exception as e: | ||
LOG.exception(e) | ||
self._revert_connection() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop can cause the gateway stuck, probably, it will be better to add check is the gateway stopped or no, to avoid hold before stop.