Closed nilsmau closed 4 years ago
@nilsmau
'Lost connection to MySQL server during query'
Is there anything interesting in your mysql server logs?
@bdraco I am unable to access the MySQL server logs (hoster says its impossible for a shared server - only logging errors). Using the same (Hassio) user credentials for logging in and querying the DB, directly or remotely shows no issue. Waiting for further feedback from hoster, as I now specifically asked for error logs. ! Bear with me...
Hassio reboot didn't change anything. More errors appear in log today. maybe those help:
[SQL: SELECT states.state_id AS states_state_id, states.domain AS states_domain, states.entity_id AS states_entity_id, states.state AS states_state, states.attributes AS states_attributes, states.event_id AS states_event_id, states.last_changed AS states_last_changed, states.last_updated AS states_last_updated, states.created AS states_created, states.context_id AS states_context_id, states.context_user_id AS states_context_user_id
FROM states
WHERE states.last_updated >= %s AND states.last_updated < %s AND states.entity_id IN (%s) ORDER BY states.last_updated DESC
LIMIT %s]
[parameters: (datetime.datetime(2020, 4, 2, 18, 31, 21, 129687, tzinfo=<UTC>), datetime.datetime(2020, 4, 2, 22, 0, 0, 12415, tzinfo=<UTC>), 'binary_sensor.wasserpumpe_running', 1)]
(Background on this error at: http://sqlalche.me/e/e3q8)
2020-04-03 05:55:56 ERROR (SyncWorker_2) [homeassistant.components.recorder.util] Error executing query: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
[SQL: SELECT states.state_id AS states_state_id, states.domain AS states_domain, states.entity_id AS states_entity_id, states.state AS states_state, states.attributes AS states_attributes, states.event_id AS states_event_id, states.last_changed AS states_last_changed, states.last_updated AS states_last_updated, states.created AS states_created, states.context_id AS states_context_id, states.context_user_id AS states_context_user_id
FROM states
WHERE states.last_updated >= %s AND states.last_updated < %s AND states.entity_id IN (%s) ORDER BY states.last_updated DESC
LIMIT %s]
[parameters: [immutabledict({})]]
2020-04-03 05:55:56 ERROR (SyncWorker_2) [homeassistant.components.recorder.util] Error executing query: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
[SQL: SELECT states.state_id AS states_state_id, states.domain AS states_domain, states.entity_id AS states_entity_id, states.state AS states_state, states.attributes AS states_attributes, states.event_id AS states_event_id, states.last_changed AS states_last_changed, states.last_updated AS states_last_updated, states.created AS states_created, states.context_id AS states_context_id, states.context_user_id AS states_context_user_id
FROM states
WHERE states.last_updated >= %s AND states.last_updated < %s AND states.entity_id IN (%s) ORDER BY states.last_updated DESC
LIMIT %s]
[parameters: [immutabledict({})]]
2020-04-03 05:55:56 ERROR (SyncWorker_2) [homeassistant.components.recorder.util] Error executing query: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
[SQL: SELECT states.state_id AS states_state_id, states.domain AS states_domain, states.entity_id AS states_entity_id, states.state AS states_state, states.attributes AS states_attributes, states.event_id AS states_event_id, states.last_changed AS states_last_changed, states.last_updated AS states_last_updated, states.created AS states_created, states.context_id AS states_context_id, states.context_user_id AS states_context_user_id
FROM states
WHERE states.last_updated >= %s AND states.last_updated < %s AND states.entity_id IN (%s) ORDER BY states.last_updated DESC
LIMIT %s]
[parameters: [immutabledict({})]]
2020-04-03 05:55:56 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.wasserpumpe_an fails
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1171, in _execute_context
conn = self._revalidate_connection()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 457, in _revalidate_connection
"Can't reconnect until invalid "
sqlalchemy.exc.InvalidRequestError: Can't reconnect until invalid transaction is rolled back
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 279, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 476, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/history_stats/sensor.py", line 214, in update
self.hass, start, end, str(self._entity_id)
File "/usr/src/homeassistant/homeassistant/components/history/__init__.py", line 114, in state_changes_during_period
return states_to_json(hass, states, start_time, entity_ids)
File "/usr/src/homeassistant/homeassistant/components/history/__init__.py", line 240, in states_to_json
for state in get_states(hass, start_time, entity_ids, filters=filters):
File "/usr/src/homeassistant/homeassistant/components/history/__init__.py", line 214, in get_states
for state in execute(query)
File "/usr/src/homeassistant/homeassistant/components/recorder/util.py", line 66, in execute
row for row in (row.to_native() for row in qry) if row is not None
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3389, in __iter__
return self._execute_and_instances(context)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3414, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 982, in execute
return meth(self, multiparams, params)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 293, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1101, in _execute_clauseelement
distilled_params,
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1176, in _execute_context
e, util.text_type(statement), parameters, None, None
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1476, in _handle_dbapi_exception
util.raise_from_cause(sqlalchemy_exception, exc_info)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 398, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 152, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1171, in _execute_context
conn = self._revalidate_connection()
File "/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 457, in _revalidate_connection
"Can't reconnect until invalid "
sqlalchemy.exc.StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back
[SQL: SELECT states.state_id AS states_state_id, states.domain AS states_domain, states.entity_id AS states_entity_id, states.state AS states_state, states.attributes AS states_attributes, states.event_id AS states_event_id, states.last_changed AS states_last_changed, states.last_updated AS states_last_updated, states.created AS states_created, states.context_id AS states_context_id, states.context_user_id AS states_context_user_id
FROM states
WHERE states.last_updated >= %s AND states.last_updated < %s AND states.entity_id IN (%s) ORDER BY states.last_updated DESC
LIMIT %s]
[parameters: [immutabledict({})]]
and it is still doing
2020-04-03 05:56:27 DEBUG (SyncWorker_12) [homeassistant.components.recorder.util] converting 0 rows to native objects took 0.155605s
2020-04-03 05:56:27 DEBUG (SyncWorker_12) [homeassistant.components.recorder.util] converting 0 rows to native objects took 0.118823s
DB Server information:
Server: Localhost via UNIX socket Server-Typ: MariaDB Server-Verbindung: SSL wird nicht verwendet Dokumentation Server-Version: 10.2.25-MariaDB-10.2.25+maria~jessie-log - mariadb.org binary distribution Protokoll-Version: 10 Benutzer: USERNAME@localhost Server-Zeichensatz: UTF-8 Unicode (utf8)
What are the
wait_timeout =
interactive_timeout =
values set to in your server's my.cnf?
This is what I get for those two when querying via MySQL...:
wait_timeout = 60
interactive_timeout = 60
While I can read my.cnf, I cannot edit it (no permissions):
[mysql]
socket = /var/lib/mysql/mysqld.sock
[mysqldump]
socket = /var/lib/mysql/mysqld.sock
I am unable to modify GLOBAL wait_timeout via MySQL (permissions again), yet, I am able to set SESSION wait_timeout with
SET session wait_timeout=300;
With a timeout that low the system is not going to be able to recover before it gets disconnected again.
The default timeout for MySQL is 8 hours. Is there a reason you have the timeout set that low?
@bdraco, glad to see there is a PR to fix this from the Home Assistant side of things (I was about to propose the session timeout setting for HA). I have in parallel requested at my hoster to raise the wait_timeout. So either way, I am hopeful there is a solution to this. (the local home assistant db on the SD card of my PI has ruined two SD cards already, thus, I would like to keep using a remote (hosted) DB) Thanks!
(the local home assistant db on the SD card of my PI has ruined two SD cards already, thus, I would like to keep using a remote (hosted) DB) Thanks!
The irony is that the change that was made to increase SD card life is what is causing this issue to appear.
Do I need to do anything on #33638 to push this into the next HA release? Did I miss something?
@nilsmau Its waiting for someone to have time to review the fix.
@nilsmau if you want to try it out, you can checkout the branch and replace your recorder with this code as /config/custom_components/recorder/
@bdraco testing now as custom component
@bdraco works! thank you! Your support and your contribution in HA is much appreciated!
The problem
Recorder connects to DB (hosted on web server) at Hassio start-up and creates required tables (events, recorder_runs, schema_changes, states) And creates entries (1 each) into: recorder_runs schema_changes After that, no further entry is created. And error MySQL 2013 (see below) appears in log. Restart of Home Assistant or System (HassOS) shows no effect. It used to work before, DB usually contained appr. 4 weeks of history.
Environment
Problem-relevant
configuration.yaml
info: all IP addresses, URLs, Names etc. replaced with placeholders all referenced .yaml files are empty
Traceback/Error logs
Additional information