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

ProxySQL does not automatically reopen backend connections when the last executed query was an INSERT that generated an auto-increment #3923

Closed
hujiko opened this issue Jul 20, 2022 · 2 comments · Fixed by #3946

Comments

@hujiko
Copy link

hujiko commented Jul 20, 2022

Hey,

I am experiencing some behavior, that looks like a bug to me:

When I

  • connect through ProxySQL to my MySQL server and execute an INSERT statement (that succeeds fine)
  • then terminate the connection between MySQL and ProxySQL (by executing KILL <process id> in a separate MySQL connection
  • Then issue a simple SELECT * FROM mytable

I get the following error in the mysql client CLI:

ERROR 2013 (HY000): Lost connection to MySQL server during query

I would expect ProxySQL to reconnect to MySQL automatically without the client actually noticing anything.

I am running ProxySQL 2.4.2 on Ubuntu 20. My MySQL version is 8.0.27-18.1.
The MySQL-Cluster actually is a Galera Cluster, but as only one host is used and no read-write-splitting is configured, this should not matter.

And apparently in the exact same setup, ProxySQL does exactly this, when the last executed statement on the connection was a SELECT statement.

So the following combination works fine:

  • connect through ProxySQL to my MySQL server and execute an INSERT statement (that succeeds fine)
  • on the same connection execute a SELECT * FROM mytable
  • then terminate the connection between MySQL and ProxySQL (by executing KILL <process id> in a separate MySQL connection
  • Then issue a simple SELECT * FROM mytable

In this combination you will not see any error message in the client, as ProxySQL reconnect the backend connection automatically.

mySQL Servers:

mysql [myHost]> select * from runtime_mysql_servers;
+--------------+-------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------------+
| hostgroup_id | hostname    | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment       |
+--------------+-------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------------+
| 10           | 10.12.64.48 | 3306 | 0         | ONLINE | 1      | 0           | 200             | 0                   | 0       | 0              | testing |
+--------------+-------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------------+
1 row in set (0.00 sec)

Global Variables:

mysql [myHost]> select * from runtime_global_variables;
+----------------------------------------------------------------------+--------------------------------------------+
| variable_name                                                        | variable_value                             |
+----------------------------------------------------------------------+--------------------------------------------+
| admin-admin_credentials                                              | admin:admin;cluster1:secret1pass           |
| admin-stats_credentials                                              | stats:stats                                |
| admin-stats_mysql_connections                                        | 60                                         |
| admin-stats_mysql_connection_pool                                    | 60                                         |
| admin-stats_mysql_query_cache                                        | 60                                         |
| admin-stats_mysql_query_digest_to_disk                               | 0                                          |
| admin-stats_system_cpu                                               | 60                                         |
| admin-stats_system_memory                                            | 60                                         |
| admin-mysql_ifaces                                                   | 0.0.0.0:6032                               |
| admin-telnet_admin_ifaces                                            | (null)                                     |
| admin-telnet_stats_ifaces                                            | (null)                                     |
| admin-refresh_interval                                               | 2000                                       |
| admin-read_only                                                      | false                                      |
| admin-hash_passwords                                                 | true                                       |
| admin-vacuum_stats                                                   | true                                       |
| admin-version                                                        | 2.4.2-1-g2c8ac95                           |
| admin-cluster_username                                               | cluster1                                   |
| admin-cluster_password                                               | secret1pass                                |
| admin-cluster_check_interval_ms                                      | 200                                        |
| admin-cluster_check_status_frequency                                 | 100                                        |
| admin-cluster_mysql_query_rules_diffs_before_sync                    | 3                                          |
| admin-cluster_mysql_servers_diffs_before_sync                        | 3                                          |
| admin-cluster_mysql_users_diffs_before_sync                          | 3                                          |
| admin-cluster_proxysql_servers_diffs_before_sync                     | 3                                          |
| admin-cluster_mysql_variables_diffs_before_sync                      | 3                                          |
| admin-cluster_admin_variables_diffs_before_sync                      | 3                                          |
| admin-cluster_ldap_variables_diffs_before_sync                       | 3                                          |
| admin-cluster_mysql_query_rules_save_to_disk                         | true                                       |
| admin-cluster_mysql_servers_save_to_disk                             | true                                       |
| admin-cluster_mysql_users_save_to_disk                               | true                                       |
| admin-cluster_proxysql_servers_save_to_disk                          | true                                       |
| admin-cluster_mysql_variables_save_to_disk                           | true                                       |
| admin-cluster_admin_variables_save_to_disk                           | true                                       |
| admin-cluster_ldap_variables_save_to_disk                            | true                                       |
| admin-checksum_mysql_query_rules                                     | true                                       |
| admin-checksum_mysql_servers                                         | true                                       |
| admin-checksum_mysql_users                                           | true                                       |
| admin-checksum_mysql_variables                                       | true                                       |
| admin-checksum_admin_variables                                       | true                                       |
| admin-checksum_ldap_variables                                        | true                                       |
| admin-restapi_enabled                                                | false                                      |
| admin-restapi_port                                                   | 6070                                       |
| admin-web_enabled                                                    | false                                      |
| admin-web_port                                                       | 6080                                       |
| admin-web_verbosity                                                  | 0                                          |
| admin-prometheus_memory_metrics_interval                             | 61                                         |
| mysql-default_charset                                                | utf8                                       |
| mysql-default_collation_connection                                   | utf8_general_ci                            |
| mysql-shun_on_failures                                               | 5                                          |
| mysql-shun_recovery_time_sec                                         | 10                                         |
| mysql-unshun_algorithm                                               | 0                                          |
| mysql-query_retries_on_failure                                       | 1                                          |
| mysql-client_host_cache_size                                         | 0                                          |
| mysql-client_host_error_counts                                       | 0                                          |
| mysql-connect_retries_on_failure                                     | 10                                         |
| mysql-connect_retries_delay                                          | 1                                          |
| mysql-connection_delay_multiplex_ms                                  | 0                                          |
| mysql-connection_max_age_ms                                          | 0                                          |
| mysql-connect_timeout_client                                         | 10000                                      |
| mysql-connect_timeout_server                                         | 10000                                      |
| mysql-connect_timeout_server_max                                     | 10000                                      |
| mysql-enable_client_deprecate_eof                                    | true                                       |
| mysql-enable_server_deprecate_eof                                    | true                                       |
| mysql-enable_load_data_local_infile                                  | false                                      |
| mysql-eventslog_filename                                             |                                            |
| mysql-eventslog_filesize                                             | 104857600                                  |
| mysql-eventslog_default_log                                          | 0                                          |
| mysql-eventslog_format                                               | 1                                          |
| mysql-auditlog_filename                                              |                                            |
| mysql-auditlog_filesize                                              | 104857600                                  |
| mysql-handle_unknown_charset                                         | 1                                          |
| mysql-free_connections_pct                                           | 10                                         |
| mysql-connection_warming                                             | false                                      |
| mysql-session_idle_ms                                                | 1                                          |
| mysql-have_ssl                                                       | false                                      |
| mysql-have_compress                                                  | true                                       |
| mysql-interfaces                                                     | 0.0.0.0:6033                               |
| mysql-log_mysql_warnings_enabled                                     | false                                      |
| mysql-monitor_enabled                                                | false                                      |
| mysql-monitor_history                                                | 60000                                      |
| mysql-monitor_connect_interval                                       | 200000                                     |
| mysql-monitor_connect_timeout                                        | 600                                        |
| mysql-monitor_ping_interval                                          | 200000                                     |
| mysql-monitor_ping_max_failures                                      | 3                                          |
| mysql-monitor_ping_timeout                                           | 1000                                       |
| mysql-monitor_read_only_interval                                     | 1000                                       |
| mysql-monitor_read_only_timeout                                      | 800                                        |
| mysql-monitor_read_only_max_timeout_count                            | 3                                          |
| mysql-monitor_replication_lag_group_by_host                          | false                                      |
| mysql-monitor_replication_lag_interval                               | 10000                                      |
| mysql-monitor_replication_lag_timeout                                | 1000                                       |
| mysql-monitor_replication_lag_count                                  | 1                                          |
| mysql-monitor_groupreplication_healthcheck_interval                  | 5000                                       |
| mysql-monitor_groupreplication_healthcheck_timeout                   | 800                                        |
| mysql-monitor_groupreplication_healthcheck_max_timeout_count         | 3                                          |
| mysql-monitor_groupreplication_max_transactions_behind_count         | 3                                          |
| mysql-monitor_groupreplication_max_transactions_behind_for_read_only | 1                                          |
| mysql-monitor_galera_healthcheck_interval                            | 5000                                       |
| mysql-monitor_galera_healthcheck_timeout                             | 800                                        |
| mysql-monitor_galera_healthcheck_max_timeout_count                   | 3                                          |
| mysql-monitor_username                                               | monitor                                    |
| mysql-monitor_password                                               | monitor                                    |
| mysql-monitor_replication_lag_use_percona_heartbeat                  |                                            |
| mysql-monitor_query_interval                                         | 60000                                      |
| mysql-monitor_query_timeout                                          | 100                                        |
| mysql-monitor_slave_lag_when_null                                    | 60                                         |
| mysql-monitor_threads_min                                            | 8                                          |
| mysql-monitor_threads_max                                            | 128                                        |
| mysql-monitor_threads_queue_maxsize                                  | 128                                        |
| mysql-monitor_wait_timeout                                           | true                                       |
| mysql-monitor_writer_is_also_reader                                  | true                                       |
| mysql-max_allowed_packet                                             | 67108864                                   |
| mysql-tcp_keepalive_time                                             | 0                                          |
| mysql-use_tcp_keepalive                                              | false                                      |
| mysql-automatic_detect_sqli                                          | false                                      |
| mysql-firewall_whitelist_enabled                                     | false                                      |
| mysql-firewall_whitelist_errormsg                                    | Firewall blocked this query                |
| mysql-throttle_connections_per_sec_to_hostgroup                      | 1000000                                    |
| mysql-max_transaction_idle_time                                      | 14400000                                   |
| mysql-max_transaction_time                                           | 14400000                                   |
| mysql-multiplexing                                                   | true                                       |
| mysql-log_unhealthy_connections                                      | true                                       |
| mysql-enforce_autocommit_on_reads                                    | false                                      |
| mysql-autocommit_false_not_reusable                                  | false                                      |
| mysql-autocommit_false_is_transaction                                | false                                      |
| mysql-verbose_query_error                                            | false                                      |
| mysql-hostgroup_manager_verbose                                      | 1                                          |
| mysql-binlog_reader_connect_retry_msec                               | 3000                                       |
| mysql-threshold_query_length                                         | 524288                                     |
| mysql-threshold_resultset_size                                       | 4194304                                    |
| mysql-query_digests_max_digest_length                                | 2048                                       |
| mysql-query_digests_max_query_length                                 | 65000                                      |
| mysql-query_digests_grouping_limit                                   | 3                                          |
| mysql-query_digests_groups_grouping_limit                            | 0                                          |
| mysql-wait_timeout                                                   | 28800000                                   |
| mysql-throttle_max_bytes_per_second_to_client                        | 0                                          |
| mysql-throttle_ratio_server_to_client                                | 0                                          |
| mysql-max_connections                                                | 2048                                       |
| mysql-max_stmts_per_connection                                       | 20                                         |
| mysql-max_stmts_cache                                                | 10000                                      |
| mysql-mirror_max_concurrency                                         | 16                                         |
| mysql-mirror_max_queue_length                                        | 32000                                      |
| mysql-default_max_latency_ms                                         | 1000                                       |
| mysql-default_query_delay                                            | 0                                          |
| mysql-default_query_timeout                                          | 10000                                      |
| mysql-query_processor_iterations                                     | 0                                          |
| mysql-query_processor_regex                                          | 1                                          |
| mysql-set_query_lock_on_hostgroup                                    | 1                                          |
| mysql-reset_connection_algorithm                                     | 2                                          |
| mysql-auto_increment_delay_multiplex                                 | 5                                          |
| mysql-auto_increment_delay_multiplex_timeout_ms                      | 10000                                      |
| mysql-long_query_time                                                | 1000                                       |
| mysql-query_cache_size_MB                                            | 256                                        |
| mysql-ping_interval_server_msec                                      | 10000                                      |
| mysql-ping_timeout_server                                            | 200                                        |
| mysql-default_schema                                                 | information_schema                         |
| mysql-poll_timeout                                                   | 2000                                       |
| mysql-poll_timeout_on_failure                                        | 100                                        |
| mysql-server_capabilities                                            | 569899                                     |
| mysql-server_version                                                 | 5.5.30                                     |
| mysql-keep_multiplexing_variables                                    | tx_isolation,transaction_isolation,version |
| mysql-kill_backend_connection_when_disconnect                        | true                                       |
| mysql-client_session_track_gtid                                      | true                                       |
| mysql-sessions_sort                                                  | true                                       |
| mysql-session_idle_show_processlist                                  | true                                       |
| mysql-show_processlist_extended                                      | 0                                          |
| mysql-commands_stats                                                 | true                                       |
| mysql-query_digests                                                  | true                                       |
| mysql-query_digests_lowercase                                        | false                                      |
| mysql-query_digests_replace_null                                     | false                                      |
| mysql-query_digests_no_digits                                        | false                                      |
| mysql-query_digests_normalize_digest_text                            | false                                      |
| mysql-query_digests_track_hostname                                   | false                                      |
| mysql-query_digests_keep_comment                                     | false                                      |
| mysql-servers_stats                                                  | true                                       |
| mysql-default_reconnect                                              | true                                       |
| mysql-ssl_p2s_ca                                                     |                                            |
| mysql-ssl_p2s_capath                                                 |                                            |
| mysql-ssl_p2s_cert                                                   |                                            |
| mysql-ssl_p2s_key                                                    |                                            |
| mysql-ssl_p2s_cipher                                                 |                                            |
| mysql-ssl_p2s_crl                                                    |                                            |
| mysql-ssl_p2s_crlpath                                                |                                            |
| mysql-stacksize                                                      | 1048576                                    |
| mysql-threads                                                        | 4                                          |
| mysql-init_connect                                                   |                                            |
| mysql-ldap_user_variable                                             |                                            |
| mysql-add_ldap_user_comment                                          |                                            |
| mysql-default_tx_isolation                                           | READ-COMMITTED                             |
| mysql-default_session_track_gtids                                    | OFF                                        |
| mysql-connpoll_reset_queue_length                                    | 50                                         |
| mysql-min_num_servers_lantency_awareness                             | 1000                                       |
| mysql-aurora_max_lag_ms_only_read_from_replicas                      | 2                                          |
| mysql-stats_time_backend_query                                       | false                                      |
| mysql-stats_time_query_processor                                     | false                                      |
| mysql-query_cache_stores_empty_result                                | true                                       |
+----------------------------------------------------------------------+--------------------------------------------+
196 rows in set (0.00 sec)

Galera Hostgroups

mysql [myHost]> select * from runtime_mysql_galera_hostgroups;
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
| writer_hostgroup | backup_writer_hostgroup | reader_hostgroup | offline_hostgroup | active | max_writers | writer_is_also_reader | max_transactions_behind | comment |
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
| 10               | 11                      | 12               | 13                | 1      | 99          | 1                     | 99                      | abc     |
+------------------+-------------------------+------------------+-------------------+--------+-------------+-----------------------+-------------------------+---------+
1 row in set (0.00 sec)

Query Rules:

mysql [myHost]> select * from runtime_mysql_query_rules;
Empty set (0.00 sec)
@hujiko hujiko changed the title ProxySQL does not automatically reopening backend connections when the last executed query was an INSERT ProxySQL does not automatically reopen backend connections when the last executed query was an INSERT Jul 20, 2022
@renecannao
Copy link
Contributor

I think the subject of this issue should be: "[...] was an INSERT that generated an auto-increment" .
If proxysql doesn't automatically use a different backend connection it means that it really needed that specific connection = multiplexing was disabled.
If multiplexing is disabled, most probably your INSERT generated an auto-increment value. That causes multiplexing to be disabled for 5 queries, due to mysql-auto_increment_delay_multiplex set to 5.
Please try to set mysql-auto_increment_delay_multiplex to 0 and see if the issue goes away.

@mirostauder
Copy link
Collaborator

After some testing we can confirm that
multiplexing does not behave as expected in this case.
We will investigate how to fix this issue.

@hujiko hujiko changed the title ProxySQL does not automatically reopen backend connections when the last executed query was an INSERT ProxySQL does not automatically reopen backend connections when the last executed query was an INSERT that generated an auto-increment Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants