Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduler logs "Error preparing query" and does not auto-recover #359

Closed
JanCeuleers opened this issue May 23, 2021 · 4 comments
Closed
Assignees
Labels
bug:general General Bugs
Milestone

Comments

@JanCeuleers
Copy link
Contributor

mythbackend.log

  • Platform: Ubuntu 20.04

  • MythTV version: v31.0+fixes

  • Package version: v31.0+fixes.202105172232.f8c59ee69d~ubuntu20.04.1

  • Component: Backend (scheduler)

Multiple users, including myself, are reporting on the users mailing list that recordings are failing at unpredictable times. It is unclear what triggers this condition. Symptoms include:

  • Scheduled recordings do not occur.
  • The list of upcoming recordings is empty.
  • The scheduler logs "Error preparing query", and does not recover its database connection.
  • Running mythutil --resched does NOT cause the backend to recover.
  • Restarting the backend does recover from this issue (until it next occurs, which might be hours or days later).

I attach multiple days' worth of logs, since I don't know how to select a sensible subset. You can find occurrences of the issue by searching for "Error preparing query", noting that the first hit is NOT an example of this issue because in this instance the backend does manage to reestablish its database connection.

@billmeek
Copy link
Contributor

The cause (at least for MySQL) is a new error code introduced in 8.0.24. The existing logic
in libs/libmythbase/mythdbcon.cpp didn't automatically reconnect to the server.

https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html

  Error number: 4031; Symbol: ER_CLIENT_INTERACTION_TIMEOUT; SQLSTATE: HY000

  Message: The client was disconnected by the server because of inactivity. See wait_timeout
  and interactive_timeout for configuring this behavior.

  ER_CLIENT_INTERACTION_TIMEOUT was added in 8.0.24.

Until the fix is released, increasing the default 8 hour wait_timeout is a known workaround
From users on the Forum.

[mysqld]
wait_timeout = 172800

The 4031 error code has a different meaning in MariaDB. Open issue for MythTV:
https://mariadb.com/kb/en/mariadb-error-codes

@billmeek billmeek self-assigned this May 24, 2021
@billmeek billmeek added the bug:general General Bugs label May 24, 2021
@billmeek billmeek added this to the 31.1 milestone May 24, 2021
@JanCeuleers
Copy link
Contributor Author

I just found out that this issue does not only affect the backend as I initially reported, but also the frontend. That is: I just came back to a frontend that had been left running idle for many hours, and it could not find any recordings. Restarting the frontend recovered from this situation.

The frontend's logfile also contains the signature "Error preparing query" lines.

Once again I attach an unfiltered mythfrontend.log -- as I said you can find an occurrence of this issue by searching for "Error preparing query".
mythfrontend.log

billmeek pushed a commit that referenced this issue May 25, 2021
A new error code was introduced in MySQL client v8.0.24 that
mythdbcon.cpp didn't handle. Users would loose the ability
to make any recordings.

Reported on the -users list and Forum for Ubuntu 20.04 users
after a recent updat to mysql* v8.0.25 and MythTV v31.0 or
master. Two MariaDB users also reported.

Tests with wait_timeout set to 300 (seconds).

18.04 (which doesn't have the problem):
Scheduler scheduler.cpp:2310 (HandleReschedule) - Reschedule requested for PLACE PrepareToRecord
Scheduler mythdbcon.cpp:947 (lostConnectionCheck) - SQL Native Error Code: 2006
Scheduler mythdbcon.cpp:260 (Reconnect) - MySQL reconnected successfully

20.04:
Scheduler scheduler.cpp:2309 (HandleReschedule) - Reschedule requested for MATCH 0 0 0 - MythUtilCommand
Scheduler mythdbcon.cpp:879 (prepare) - SQL Native Error Code: 4031
Scheduler mythdbcon.cpp:260 (Reconnect) - MySQL reconnected successfully

No testing on MariaDB has been yet.

Refs #359
@mtraxiot
Copy link

mtraxiot commented May 27, 2021

I also have the same issue, let me know if you need any more examples:
as above to recover , I need to restart backend service almost every other day.

E Scheduler mythdbcon.cpp:843 (prepare) Error preparing query: DELETE recordmatch FROM recordmatch, channel WHERE recordmatch.chanid = channel.chanid
E Scheduler mythdbcon.cpp:845 (prepare) Driver error was [2/0]:#012QMYSQL3: Unable to prepare statement#012Database error was:#12

@xipmix
Copy link

xipmix commented May 28, 2021

Another data point.
I updated my mariadb server to use the longer timeout, and restarted it.
However I neglected to restart mythtv-backend.service as well.
This caused the mythtv-status service to stop, and errors to appear like

mythbackend[1025679]: E HttpServer64 mythdbcon.cpp:843 (prepare) Error preparing query: SELECT data FROM settings WHERE value = :KEY AND hostname ...

I restarted the backend, and mythtv-status. and things seemed to come good again.
Versions

  • Ubuntu 20.04.2 LTS amd64
  • libmysqlclient21 8.0.25-0ubuntu0.20.04.1
  • mariadb-client-core-10.3 1:10.3.29-0ubuntu0.20.04.1
  • mariadb-server 1:10.3.29-0ubuntu0.20.04.1.

mythtv 2:31.0+fixes.202105172232.f8c59ee69d~ubuntu20.04.1

billmeek pushed a commit that referenced this issue May 29, 2021
A new error code was introduced in MySQL client v8.0.24 that
mythdbcon.cpp didn't handle. Users would loose the ability
to make any recordings.

Reported on the -users list and Forum for Ubuntu 20.04 users
after a recent updat to mysql* v8.0.25 and MythTV v31.0 or
master. Two MariaDB users also reported.

Tests with wait_timeout set to 300 (seconds).

18.04 (which doesn't have the problem):
Scheduler scheduler.cpp:2310 (HandleReschedule) - Reschedule requested for PLACE PrepareToRecord
Scheduler mythdbcon.cpp:947 (lostConnectionCheck) - SQL Native Error Code: 2006
Scheduler mythdbcon.cpp:260 (Reconnect) - MySQL reconnected successfully

20.04:
Scheduler scheduler.cpp:2309 (HandleReschedule) - Reschedule requested for MATCH 0 0 0 - MythUtilCommand
Scheduler mythdbcon.cpp:879 (prepare) - SQL Native Error Code: 4031
Scheduler mythdbcon.cpp:260 (Reconnect) - MySQL reconnected successfully

No testing on MariaDB has been yet.

Fixes #359

(cherry picked from commit e55471f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug:general General Bugs
Projects
None yet
Development

No branches or pull requests

4 participants