5

This one is killing me. We have an ASP.NET/Mono application on a MySQL database. For months we've been plagued by a completely random but consistent occurrence of "Unable to connect to any of the specified MySQL hosts". I'm by no means a MySQL pro, and I hope this is something silly.

Specifics:
MySQL 5.5.17
MySQL Connector/Net 6.4.4
Mono 2.10.8
MonoDevelop 2.8.6.5

Connection string: SERVER=localhost,3306;DATABASE=xxx;UID=xxx;PWD=xxx;CONNECTION TIMEOUT=90;Encrypt=false;

Max_connections is set to 150. There are never more than 5 connections, and they are all active (probably due to the pooling).

  • The application is C# ASP.NET 3.5. Runs solid as a rock for years on Windows/IIS. Nine months ago our market led us to get off Windows, so we (easily I might add) moved the whole thing to Mono/Apache.

  • The issue only occurs on the Mono side, but that's critical since we've retired our Windows support.

  • Happens on average about 10 times an hour, but spacing varies wildly.

  • The issue has been witnessed in the following configurations:

Ubuntu 11/Apache2/mod_mono
OSX Lion/Apacke2/mod_mono
Ubuntu 11/xsp2/MonoDevelop debug server
OSX Lion/xsp2/MonoDevelop debug server

  • Have messed with keepalive, wait_timeout, connectionreset, etc to no avail. Timings seem to have no effect. The error is instantaneous on conn.open - not after any connection timeout.

  • Here's a clue - the app absolutely will not run with Pooling=false. Nearly every connection attempt fails. Of course I want pooling on, but I'm not sure why it wouldn't work without.

  • The application has a built in "heartbeat" (user's session in the database) - every 2 minutes.

  • The most maddening of all? It absolutely cannot be reproduced on demand in a running environment - it's random. I've examined query sizes, execution times, etc.

  • In exactly one scenario can I make it happen: On initial startup of an Ubuntu server or OSX, the very first time Mono makes it's first connection to MySQL - it will happen then. After that, it's anybody's guess.

hikaru
  • 1,966
  • 1
  • 20
  • 27
  • How about max_connections limits? You could be hitting the max allowed at various times. – Marc B Feb 20 '12 at 23:29
  • Seems unlikely given that it happens on first connection – DNA Feb 20 '12 at 23:35
  • +1 for a well asked question, but I think it would fare better on serverfault.com – Mike Purcell Feb 20 '12 at 23:43
  • It doesn't seem random to me. I imagine it happens whenever the connection pool needs to open a new connection. You've got a connection timeout of 90 seconds, so if you start up a new server and limit access so only you can hit the server, then (if I'm right) you should see the error every time you let the connection(s) in the connection pool timeout (i.e., 90+ seconds of inactivity). – John Pick Feb 21 '12 at 01:07
  • Good points - I updated the question accordingly. John, isn't connection timeout the amount of time the client will wait for a response when *requesting* a connection? Changing it has no effect. Besides, the pool is maintaining the "real" connections, not my code. I'm nearly convinced it's the pool giving me this error. – hikaru Feb 21 '12 at 13:48

1 Answers1

0

Ok, this is old, but i lost so much time on this, i've to share this life saving article i finally found : Getting Mono and Mysql to play nice together

And i sum up for the case the link end up in 404 someday : EVERY variable of the connection string MUST be defined. So, yes, that includes port, which i never had to define in a connection string ever in my life before.

For me it solved the problem.

Laloutre
  • 173
  • 2
  • 11