arabcoders / watchstate

Self-hosted service to sync your plex, jellyfin and emby play state. without relying on 3rd-party external services.
MIT License
481 stars 9 forks source link

[BUG] Re-create SQL prepare statements when encountering an error. #548

Closed arabcoders closed 2 months ago

arabcoders commented 2 months ago

Thanks to the new logging i was able to trace phantom db error that was happening at random times due to various reasons. The gist of it is that, in recent SQLITE versions, whenever an error occurs, the prepared statements must be recreated and not be reused. We reuse the statements to gain huge speed. We need to find a way fix this issue while retaining this advantage. If there is no way, we probably will keep it as it is and mark it WONTFIX. the advantage is just too great to give up.

The error manifest itself as something like

[2024-09-08T00:18:15.473632+03:00] logger.ERROR: DirectMapper: Exception 'App\Libs\Exceptions\DBLayerException' was thrown unhandled in 'XX' add. 'SQLSTATE[HY000]: General error: 21 bad parameter or other API misuse' at '/src/Libs/Database/PDO/PDOAdapter.php:843'.

Ref: https://github.com/teamtnt/tntsearch/pull/126

arabcoders commented 2 months ago

We have improved how we handle the error at PDOAdapter level, it's only for the prepared statements we pre-set in the class https://github.com/arabcoders/watchstate/commit/68e63d40047b2761f05e073df7a5ed391f0c7a98

arabcoders commented 2 months ago

So far it seems to have been solved by our latest dev commits.