MySQL: After a certain amount of time/transactions connections freeze during spec tests
kalinon opened this issue · 4 comments
I found that after a certain amount of time/transactions (its unclear which one) spec tests will hang when running against a mysql server.
I was able to add debug and get this traced down to the DB
adapter layer where it starts to read a packet but never completes:
2023-04-26T22:01:59.604210Z DEBUG - db: Executing query -- query: "INSERT INTO `kvs` (`v`, `k`) VALUES (?, ?)", args: [nil, "foo"]
2023-04-26T22:01:59.604372Z TRACE - db: About to execute query
2023-04-26T22:01:59.604419Z TRACE - mysql: About to execute query
2023-04-26T22:01:59.604465Z TRACE - mysql: #<MySql::Connection:0x103b95a20>
2023-04-26T22:01:59.604513Z TRACE - mysql: write start - #<MySql::WritePacket:0x1074826e0>
2023-04-26T22:01:59.604564Z TRACE - mysql: write done - #<MySql::WritePacket:0x1074826e0>
2023-04-26T22:01:59.604698Z TRACE - mysql: read start - MySql::IncomingPacket[length: 5, seq: 4, remaining: 5]
I was able to complete a full spec run only if i manually closed all the connections in the connection pool.
# added to spec_helper.cr
Spec.after_each do
Granite::Connections["mysql"].not_nil!.database.pool.close
end
I will keep investigating.
Interesting. If that's true, this is probably a bug in the MySQL Adapter rather than in granite.
Interesting. If that's true, this is probably a bug in the MySQL Adapter rather than in granite.
Yeah, i found it curious. If i do the specs in random order, it will freeze at different places, but always after a majority of specs are completed. I need to verify its not just my MySQL server or something local.
The fact that it works when you force close all the connections makes me think there are being closed properly from some operations.
Which does seem like a bug in the MySQL adapter.
Does CI behave the same way? Or does it change between Crystal versions?
@crimson-knight yes, CI behaves the same as does differences between crystal versions.
Versions Tested:
Crystal: 1.6.2, 1.7.2, 1.8.1
Mysql: 5.7, 8.0