diff --git a/tuxbot/cogs/Network/functions/utils.py b/tuxbot/cogs/Network/functions/utils.py
index f2a60ca..092f92d 100644
--- a/tuxbot/cogs/Network/functions/utils.py
+++ b/tuxbot/cogs/Network/functions/utils.py
@@ -120,13 +120,24 @@ async def get_ipwhois_result(loop, ip: str) -> NoReturn | dict:
cache=Cache.MEMORY,
namespace="network",
)
-async def get_ipinfo_result(apikey: str, ip: str) -> dict:
+async def get_ipinfo_result(loop, apikey: str, ip: str) -> dict:
+ def _get_ipinfo_result(_ip: str) -> NoReturn | dict:
+ """
+ Q. Why no getHandlerAsync ?
+ A. Use of this return "Unclosed client session" and "Unclosed connector"
+ """
+ try:
+ handler = ipinfo.getHandler(apikey, request_options={"timeout": 7})
+ return (handler.getDetails(ip)).all
+ except RequestQuotaExceededError:
+ return {}
+
try:
- handler = ipinfo.getHandlerAsync(
- apikey, request_options={"timeout": 7}
+ return await asyncio.wait_for(
+ loop.run_in_executor(None, _get_ipinfo_result, str(ip)),
+ timeout=8,
)
- return (await handler.getDetails(ip)).all
- except RequestQuotaExceededError:
+ except asyncio.exceptions.TimeoutError:
return {}
diff --git a/tuxbot/cogs/Network/network.py b/tuxbot/cogs/Network/network.py
index c1a87eb..656ec20 100644
--- a/tuxbot/cogs/Network/network.py
+++ b/tuxbot/cogs/Network/network.py
@@ -103,6 +103,8 @@ class Network(commands.Cog):
self._peeringdb_net = await s.json()
except asyncio.exceptions.TimeoutError:
pass
+ else:
+ log.log(logging.INFO, "_update_peering_db")
# =========================================================================
# =========================================================================
@@ -126,7 +128,7 @@ class Network(commands.Cog):
ip_hostname = await get_hostname(self.bot.loop, str(ip_address))
ipinfo_result = await get_ipinfo_result(
- self.__config.ipinfoKey, ip_address
+ self.bot.loop, self.__config.ipinfoKey, ip_address
)
ipwhois_result = await get_ipwhois_result(self.bot.loop, ip_address)
diff --git a/tuxbot/core/bot.py b/tuxbot/core/bot.py
index 810b04d..75f1710 100644
--- a/tuxbot/core/bot.py
+++ b/tuxbot/core/bot.py
@@ -332,7 +332,10 @@ class Tux(commands.AutoShardedBot):
self.console.log(
"Canceling", task.get_name(), f"({task.get_coro()})"
)
- task.cancel()
+ try:
+ task.cancel()
+ except Exception as e:
+ self.console.log(e)
await asyncio.gather(*pending, return_exceptions=False)
await super().close()