Migrating from MySql: MariaDB server closing client connections unexpectedly

旧城冷巷雨未停 提交于 2019-12-04 00:20:22

We encountered the same problem recently, due to a combination of incorrect parameters. This error is caused by your web instance trying to use a connection that is no longer a valid one.

This can be resolved by making sure the following parameters are correct:

  1. You have a validationQuery configured for your database connection. i.e. validationQuery="SELECT 1" in case of mariadb, in the server configuration.
  2. You have the wait_timeout set to a reasonable value. 8 hours keepAlive seems a bit optimistic, we are now using wait_timeout=180
  3. Make sure the validationInterval, which you can also set in the server configuration (server.xml in case of a tomcat setup), is set to a value that is lower than the wait_timeout value. I reduced the wait_timeout to 15s in one case, with the validationInterval value being higher than that, which caused the error to still appear at times. Now it is set to validationInterval=60, combined with the wait_timeout=180 which should catch any broken connections in time.

You can try to increase 'wait_timeout' instead of 'interactive_timeout'. 8-12 hours until error correlates quite well with the default value of wait_timeout which is 10 hours. JDBC driver does not set interactive client flag when connecting, so change to 'interactive_timeout' might have no effect. I also replied to the cross-post in Maria KB ;)

Toni_Mashengo

I also had an error like this one Could not connect to localhost:3306: unexpected end of stream, read 0 bytes from 4

My architecture was an webapp of Tomcat that was inserting data into MariaDB.

I was using the connector version 1.5.1RC! I switched to the 1.3.1 connector version and now runs fine!

I also faced this issue. The issue goes away with lowering the wait_timeout.

SHOW SESSION VARIABLES LIKE 'wait_timeout'; ->> would be 8 hours. which is huge.
SET session wait_timeout=300; ->> this should fix the issue.

Look at

SHOW VARIABLES LIKE 'max_connections';
SHOW GLOBAL STATUS LIKE '%connect%';

Compare the my.cnf values between the two systems; you may see a difference in things like above that make a difference. If the problem is still not obvious, please provide those values for further discussion.

According to the findings in this article you could get away with two options:

  1. You should try turning innodb_file_per_table off

    or...

  2. Increasing the open file limits, this tells you the current value on yout machine $ ulimit -n, should you be running on high spec machines

I think that the problem is with MariaDB Connector/J. Try to use a stable one like MariaDB Connector/J 1.2.3 for example. Also, study Failover behaviour with Basic failover when autoReconnect is set to true or Standard failover.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!