Reputation: 6444
I recently made the switch from Ubuntu to OSX. Now I cannot run RSpec tests anymore, even though it worked on Ubuntu.
The first testcase will always return:
Failure/Error: @match.save!
ActiveRecord::StatementInvalid:
Mysql2::Error: MySQL server has gone away: ROLLBACK TO SAVEPOINT active_record_1
Then every testcase thereafter:
Failure/Error: Unable to find matching line from backtrace
Mysql2::Error:
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (61)
My database.yml just connects to the DB via socket /tmp/mysql.sock
. Setting reconnect:true
makes no difference.
I installed mysql via homebrew. I also already re-installed it as mentioned here to make sure it's not a problem of the mysql installation.
I also increased the mysql max_allowed_packet as suggested here (I tried up to 4096M and verified the setting using show variables like 'max_allowed_packet'
, but still no success.
Setting use_transactional_fixtures:false
as suggested here and using Database Cleaner did not help either.
I narrowed the problem down to only affect test cases using before_save triggers in the model. When triggering an affected method in development mode the same problem occurs:
Mysql2::Error: Lost connection to MySQL server during query: UPDATE ...
Meanwhile I also removed the homebrew mysql server and installed the one from the official website - without any luck.
Here is the mysql error log, which looked similar for both mysql server versions (official+homebrew): Gist
Following is the problematic statement. I can also run it in isolation in the MySQL console and it will reliable crash the server:
UPDATE bets SET points = 2 WHERE betsession_id IN (1, 3, 5, 7, 10, 16, 31, 33, 35, 39, 42, 44, 49, 50, 56, 58, 61) AND match_id = 1583 AND (home_score = guest_score) AND (home_score = 2 OR home_score = 0);
I can strip it down to
UPDATE bets SET points = 2 WHERE (home_score = guest_score);
which sometimes crashes the server. Adding the AND (home_score = 0 OR home_score = 2)
will however reliably lead to a crash. Any of the 2 WHERE conditions in isolation tend to work well. Is there some kind of internal memory buffer that I need to increase?
Upvotes: 2
Views: 3560
Reputation: 5056
I can tell from the posted log it is an internal error which causes the connection to close and not a connection problem. So focus on the server itself and not the connection.
UPDATE: It seems like a bug in 5.6. Try Downgrading
Upvotes: 3