mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 12:10:06 -03:30
reconnect when a vanilla server disconnect happens
This commit is contained in:
@@ -93,7 +93,7 @@ class WebsocketTask():
|
|||||||
try:
|
try:
|
||||||
async with aiohttp.ClientSession(headers={'secret': secret_val},
|
async with aiohttp.ClientSession(headers={'secret': secret_val},
|
||||||
timeout=timeout) as session:
|
timeout=timeout) as session:
|
||||||
async with session.ws_connect(uri, ssl=self.verify_ssl) as websocket:
|
async with session.ws_connect(uri, ssl=self.verify_ssl, heartbeat=20) as websocket:
|
||||||
self.stats.record_connection_established()
|
self.stats.record_connection_established()
|
||||||
attempt = 0
|
attempt = 0
|
||||||
await self.run_loop(websocket)
|
await self.run_loop(websocket)
|
||||||
@@ -105,17 +105,14 @@ class WebsocketTask():
|
|||||||
raise
|
raise
|
||||||
except client_exceptions.ClientConnectorError as e:
|
except client_exceptions.ClientConnectorError as e:
|
||||||
logger.warn(f"Failed to connect to {self.remote_host}: '{e}'. Reconnecting ...")
|
logger.warn(f"Failed to connect to {self.remote_host}: '{e}'. Reconnecting ...")
|
||||||
self.stats.record_connection_lost()
|
|
||||||
self.start(attempt=attempt + 1)
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
logger.warn(f"Timeout while trying to connect to {self.remote_host}. Reconnecting ...")
|
logger.warn(f"Timeout while trying to connect to {self.remote_host}. Reconnecting ...")
|
||||||
self.stats.record_connection_lost()
|
|
||||||
self.start(attempt=attempt + 1)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Early on, this is our canary. I'm not sure what exceptions we can really encounter.
|
# Early on, this is our canary. I'm not sure what exceptions we can really encounter.
|
||||||
logger.warn(f"Websocket broadcast client exception {type(e)} {e}")
|
logger.warn(f"Websocket broadcast client exception {type(e)} {e}")
|
||||||
self.stats.record_connection_lost()
|
|
||||||
self.start(attempt=attempt + 1)
|
self.stats.record_connection_lost()
|
||||||
|
self.start(attempt=attempt + 1)
|
||||||
|
|
||||||
def start(self, attempt=0):
|
def start(self, attempt=0):
|
||||||
self.async_task = self.event_loop.create_task(self.connect(attempt=attempt))
|
self.async_task = self.event_loop.create_task(self.connect(attempt=attempt))
|
||||||
|
|||||||
Reference in New Issue
Block a user