The goal of this issue is to make sure that the error
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away will not show again (randomly) in Travis CI.
Example randomly failed build: https://travis-ci.org/piwik/piwik/jobs/39441245
Also discussed in https://github.com/travis-ci/travis-ci/issues/2250
Our FAQ explains to our users how to solve this: How do I fix the error “Mysql Server has gone away”?
my tests didn't work so I asked Travis here https://github.com/travis-ci/travis-ci/issues/2250#issuecomment-61037684
FYI I got the same error while running the system tests on AWS.
There were some users having the same error in the forums. Not sure if and how it could be caused by piwik
Didn't know this is still a thing... I added https://github.com/piwik/piwik/commit/8e58b758fb03d8d38db6a6c78f824cb68ee68668 a while ago which seemed to solve it but probably not. Or Is maybe performSetup no longer executed when executing system tests?
Actually, the system tests perform API requests so we might have to execute this query as well in each API/index.php request for tests? Might be worth a try. Not sure if it fixes it though.
Another occurrence https://travis-ci.org/piwik/piwik/jobs/39922102
I'm deleting the branch where i was running some tests:
+ # Prevent Mysql has gone away + - mysql -e "SHOW VARIABLES LIKE 'max_allowed_packet';" + - echo -e "[server]\nmax_allowed_packet=64M" | sudo tee -a /etc/mysql/conf.d/drupal.cnf + - sudo service mysql reload + - mysql -e "SET GLOBAL wait_timeout=300;" + - mysql -e "SHOW VARIABLES LIKE 'max_allowed_packet';"
Somehow this happens less often now. it seems this issue is tightly coupled to whatever VMs Travis gives us. some of the VMs are failing heaps while others always work fine.
Just as I write it happens less often I'm seeing today some example where it occurs eg. https://travis-ci.org/piwik/piwik/jobs/44512857
Another one in https://travis-ci.org/piwik/piwik/jobs/46159944
From a latest build, the stack trace:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' in /home/travis/build/piwik/piwik/libs/Zend/Db/Adapter/Pdo/Abstract.php:263 Stack trace: [...] #5 /home/travis/build/piwik/piwik/tests/PHPUnit/Framework/Fixture.php(839): Piwik\DbHelper::dropDatabase('piwik_tests') #6 /home/travis/build/piwik/piwik/tests/PHPUnit/Framework/Fixture.php(295): Piwik\Tests\Framework\Fixture->dropDatabase() #7 /home/travis/build/piwik/piwik/tests/PHPUni [the stack trace is truncated here unfortunately]
We can see that the query that failed is
DROP DATABASE, which is executed in test's
tearDown(). So it might be that a test has a query that fails, which breaks the MySQL connection. Then in the tearDown,
DROP DATABASE fails because of that, and the new exceptions "overrides" the original exception in PHPUnit's log.
I had that kind of things happen in a previous project, we had to test in the database/table still existed before dropping it.
What we could try is wrap the call to
dropDatabase in a try/catch?
Well i'm join in about this one. I think there is a problem with memory. Although i tried to increase the max packet size to 64M the size is still 16M. What i did so my test will is to split it.
splitting test is a good solution but it's a really good one because each matrix set up the environment. For small projects it's could be good but for large projects like OpenScholar is not a good solution because the set up takes 20 min and you have only two matrix at a time. If someone know how to solve that i'd like to here about it.
Since we removed the PHP 5.3.3 build and only run on latest PHP I think this issue is now gone. Please re-open the issue if you still find cases of "mysql has gone away" in Piwik builds