mysqlplus icon indicating copy to clipboard operation
mysqlplus copied to clipboard

'mysqlplus' blocks the entire Ruby process when connecting to DB

Open ibc opened this issue 15 years ago • 3 comments

Hi, "mysqlplus" (and of course also "mysql") driver blocks totally the Ruby process when it's trying to connect to a MySQL server. In case the server doesn't respond then we get our Tuby application stopped forever.

Please check the following code which shows the issue: http://gist.github.com/264866

Is it possible to make MySQL connection non-blocking?

Regards.

ibc avatar Dec 28 '09 19:12 ibc

I've reported same bug for 'pg' driver and it's fixed now (it already implemented non-blocking connection):

http://bitbucket.org/ged/ruby-pg/issue/14/pgconnconnect-blocks-forever-if-the-db-host-is#comment-100487 http://bitbucket.org/ged/ruby-pg/changeset/f5af71167dea/

ibc avatar Dec 28 '09 23:12 ibc

To create a non-blocking connection you need to provide a timeout (works in all mysql libs) as by default there is no connect timeout defined. con = Mysql.init con.options(Mysql::OPT_CONNECT_TIMEOUT, 5) # 5 second timeout

skiz avatar Feb 17 '10 23:02 skiz

Great, I didn't know such option. I will report to Sequel developer to include it. Thanks.

ibc avatar Feb 18 '10 10:02 ibc