You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clear the MySQL connection statement cache on error
Some cloud offerings like AWS Aurora allow for "zero-downtime" restarts
for patches, which preserves existing TCP connections but wipes out a
lot of server state, including the statement cache. In that scenario,
trying to execute a previously prepared statement causes an error
response with
```
HY000 Unknown prepared statement handler (<id>) given to mysql_stmt_precheck
```
which appears to be the only way to detect this scenario.
To avoid subsequent errors for the same connection, we can clear the
statement cache on the client side, causing all queries to get
re-prepared. This is basically what ActiveRecord does,[0] which we can
confirm is not vulnerable to the same issue. An even better solution
would be to re-prepare and -try the query right there, like ActiveRecord
does.
[0]: https://github.com/rails/rails/blob/main/activerecord/lib/active_record/connection_adapters/mysql2/database_statements.rb#L66-L78
0 commit comments