bug: remove some excepts that were catching propagated cancellations.

This commit is contained in:
Upstream Data
2024-04-26 13:00:16 -06:00
parent 2fbc4fcb4a
commit 5a067d60e7

View File

@@ -535,21 +535,17 @@ class MinerFactory:
async def _get_miner_type(self, ip: str) -> MinerTypes | None:
tasks = [
asyncio.create_task(self._get_miner_web(ip)),
# asyncio.create_task(self._get_miner_socket(ip)),
asyncio.create_task(self._get_miner_socket(ip)),
]
return await concurrent_get_first_result(tasks, lambda x: x is not None)
async def _get_miner_web(self, ip: str) -> MinerTypes | None:
tasks = []
try:
urls = [f"http://{ip}/", f"https://{ip}/"]
async with httpx.AsyncClient(
transport=settings.transport(verify=False)
) as session:
tasks = [
asyncio.create_task(self._web_ping(session, url)) for url in urls
]
tasks = [asyncio.create_task(self._web_ping(session, url)) for url in urls]
text, resp = await concurrent_get_first_result(
tasks,
@@ -557,23 +553,7 @@ class MinerFactory:
and self._parse_web_type(x[0], x[1]) is not None,
)
if text is not None:
mtype = self._parse_web_type(text, resp)
if mtype == MinerTypes.ANTMINER:
# could still be mara
auth = httpx.DigestAuth("root", "root")
res = await self.send_web_command(
ip, "/kaonsu/v1/brief", auth=auth
)
if res is not None:
mtype = MinerTypes.MARATHON
return mtype
except asyncio.CancelledError:
for t in tasks:
t.cancel()
try:
await t
except asyncio.CancelledError:
pass
return self._parse_web_type(text, resp)
@staticmethod
async def _web_ping(
@@ -621,12 +601,8 @@ class MinerFactory:
return MinerTypes.AURADINE
async def _get_miner_socket(self, ip: str) -> MinerTypes | None:
tasks = []
try:
commands = ["version", "devdetails"]
tasks = [
asyncio.create_task(self._socket_ping(ip, cmd)) for cmd in commands
]
tasks = [asyncio.create_task(self._socket_ping(ip, cmd)) for cmd in commands]
data = await concurrent_get_first_result(
tasks,
@@ -635,13 +611,6 @@ class MinerFactory:
if data is not None:
d = self._parse_socket_type(data)
return d
except asyncio.CancelledError:
for t in tasks:
t.cancel()
try:
await t
except asyncio.CancelledError:
pass
@staticmethod
async def _socket_ping(ip: str, cmd: str) -> str | None: