Use context manager for request channel

This commit is contained in:
Daniel A. Wozniak 2023-11-06 15:01:39 -07:00 committed by Pedro Algarvio
parent be5ef66a3a
commit 6615b5a530

View file

@ -552,19 +552,16 @@ class AsyncPubChannel:
"data": data,
"tag": tag,
}
req_channel = AsyncReqChannel.factory(self.opts)
try:
yield req_channel.send(load, timeout=60)
except salt.exceptions.SaltReqTimeoutError:
log.info(
"fire_master failed: master could not be contacted. Request timed"
" out."
)
except Exception: # pylint: disable=broad-except
log.info("fire_master failed", exc_info=True)
finally:
# SyncWrapper will call either close() or destroy(), whichever is available
req_channel.close()
with AsyncReqChannel.factory(self.opts) as channel:
try:
yield channel.send(load, timeout=60)
except salt.exceptions.SaltReqTimeoutError:
log.info(
"fire_master failed: master could not be contacted. Request timed"
" out."
)
except Exception: # pylint: disable=broad-except
log.info("fire_master failed", exc_info=True)
else:
self._reconnected = True
except Exception as exc: # pylint: disable=broad-except