Через время бот перестает выполнять команды требующие подключения к базе
Через несколько часов от перестаёт выполнять команды, которые требуют подключения к MySQL, обычные команды выполняет. Подключение реализовано через mysql-connector и пул подключений. В чём может быть проблема?
Код подключения к базе:
import mysql.connector
from bestconfig import Config
from mysql.connector import pooling
from mysql.connector import Error
config = Config() #config['version']
def getConnection():
try:
connection_pool = pooling.MySQLConnectionPool(pool_name="discord_pool",
pool_size=2,
pool_reset_session=True,
host=config['host'],
database=config['database'],
user=config['user'],
password=config['password'])
# Get connection object from a pool
connection_object = connection_pool.get_connection()
if connection_object.is_connected():
db_Info = connection_object.get_server_info()
print("Connected to MySQL database using connection pool ... MySQL Server version on ", db_Info)
cursor = connection_object.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("Your connected to - ", record)
else:
connection_object.reconnect(attempts=1, delay=0)
except Error as e:
print("Error while connecting to MySQL using Connection pool ", e)
return connection_object
Логи python:
2022-12-25 05:52:00,155 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
2022-12-25 07:09:37,816 ERROR Attempting a reconnect in 1.11s
Traceback (most recent call last):
File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/discord/gateway.py", line 372, in from_client
socket = await client.http.ws_connect(str(url))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/discord/http.py", line 536, in ws_connect
return await self.__session.ws_connect(url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/aiohttp/client.py", line 779, in _ws_connect
resp = await self.request(
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/aiohttp/client.py", line 536, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 540, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 901, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/aiohttp/connector.py", line 980, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore[return-value] # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/base_events.py", line 1063, in create_connection
sock = await self._connect_sock(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/base_events.py", line 967, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/lib/python3.11/asyncio/selector_events.py", line 634, in sock_connect
return await fut
^^^^^^^^^
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/discord/client.py", line 624, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
TimeoutError
2022-12-25 07:09:39,518 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
2022-12-25 07:27:23,366 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
2022-12-25 07:44:19,708 INFO Shard ID None has successfully RESUMED session 5a6cfa0f2871c73636a54087ddb35c3a.
Логи MySQL:
2022-12-24T23:31:25.904328Z 718 [Warning] [MY-010055] [Server] IP address '2.57.122.23' could not be resolved: Name or service not known
2022-12-25T00:43:30.330033Z 719 [Warning] [MY-010058] [Server] Hostname 'zg-1220a-127.stretchoid.com' does not resolve to '192.241.224.10'.
2022-12-25T03:47:37.608995Z 723 [Warning] [MY-010055] [Server] IP address '46.216.30.14' could not be resolved: Name or service not known
2022-12-25T03:47:37.609192Z 722 [Warning] [MY-010055] [Server] IP address '46.216.30.14' could not be resolved: Name or service not known
2022-12-25T05:31:12.652320Z 772 [Warning] [MY-010055] [Server] IP address '206.189.208.4' could not be resolved: Name or service not known
2022-12-25T06:19:41.620580Z 773 [Warning] [MY-010055] [Server] IP address '92.255.85.233' could not be resolved: Name or service not known
2022-12-25T07:45:01.564618Z 774 [Warning] [MY-010056] [Server] Host name 'pool-5-206-44-143.is74.ru' could not be resolved: Name or service not known
2022-12-25T07:45:01.565053Z 775 [Warning] [MY-010056] [Server] Host name 'pool-5-206-44-143.is74.ru' could not be resolved: Name or service not known
2022-12-25T07:48:46.702665Z 824 [Warning] [MY-010058] [Server] Hostname 'zg-1220a-17.stretchoid.com' does not resolve to '192.241.230.5'.
2022-12-25T08:52:12.885725Z 825 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:12.971229Z 826 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:13.079504Z 827 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:13.249122Z 828 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:13.418399Z 829 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:13.591984Z 830 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:13.763566Z 831 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:13.934613Z 832 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:14.112660Z 833 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:14.287298Z 834 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:14.461324Z 835 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:14.634360Z 836 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.
2022-12-25T08:52:14.809811Z 837 [Warning] [MY-010057] [Server] IP address '35.216.148.48' has been resolved to the host name '48.148.216.35.bc.googleusercontent.com', which resembles IPv4-address itself.