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

MySQL: After a certain amount of time/transactions connections freeze during spec tests #473

Open
kalinon opened this issue Apr 26, 2023 · 4 comments

Comments

@kalinon
Copy link
Contributor

kalinon commented Apr 26, 2023

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.

@robacarp
Copy link
Member

Interesting. If that's true, this is probably a bug in the MySQL Adapter rather than in granite.

@kalinon
Copy link
Contributor Author

kalinon commented Apr 26, 2023

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.

@crimson-knight
Copy link
Member

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?

@kalinon
Copy link
Contributor Author

kalinon commented Apr 27, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants