class ActiveRecord::ConnectionAdapters::TransactionManager

def after_failure_actions(transaction, error)

Deallocate invalidated prepared statements outside of the transaction
def after_failure_actions(transaction, error)
  return unless transaction.is_a?(RealTransaction)
  return unless error.is_a?(ActiveRecord::PreparedStatementCacheExpired)
  @connection.clear_cache!
end