Bugzilla – Bug 947
mysql: SlimServer needs to reconnect on lost database connections
Last modified: 2008-12-15 13:06:13 UTC
I'm using svn revision 2317 on Gentoo Linux with an mysql 4.0.22 If the server is idle for a long time, the database connection to the mysql server seems to die. After this, as soon as I switch on my squeezebox, the server dies: DBD::mysql::st execute failed: MySQL server has gone away at /home/slimserver/SlimServer_svn/slim/trunk/server/CPAN/DBIx/C ontextualFetch.pm line 51. Slim::DataStores::DBI::Track can't SELECT id, thumb, age, ct, titlesort, album, tracknum, url, tag, title, disc, fs FROM tracks WHERE url = ? : DBD::mysql::st execute failed: MySQL server has gone away at /home/slimserver/SlimServer_svn/slim/trunk/server/CPAN/DBIx /ContextualFetch.pm line 51. at /home/slimserver/SlimServer_svn/slim/trunk/server/Slim/DataStores/DBI/DBIStore.pm line 882 I think that the slimserver needs to refresh its database connection and die only after a configurable number of retries.
See Apache::DBI for a way to do this with the ping() method on a $dbh Because we aren't officially supporting mysql right now, I haven't the time to look at this. Patches welcome.
*** Bug 996 has been marked as a duplicate of this bug. ***
*** Bug 1303 has been marked as a duplicate of this bug. ***
suggest someone changes the description/keywords to include mysql - that's why duplicates keep getting resubmitted!
This problem occurs on other databases as well. MySql seems to be the primary "other" database, so I changed the summary to include the engine name.
Here's a patch that seems to solve the problem. The killMorningBug() method does the work, pinging the database every few hours. The part of the patch I don't like is how I decide whether to call the method. I just search for 'mysql' in the database source string. Any better ideas? Could we just call killMorningBug always? Or control it via a pref? -------------------------------------------------------------- Index: DataModel.pm =================================================================== --- DataModel.pm (revision 2855) +++ DataModel.pm (working copy) @@ -111,6 +111,11 @@ RootClass => "DBIx::ContextualFetch" }); + # if connected to mysql database, avoid the morning bug + if ($source =~ /mysql/i) { + killMorningBug($dbh); + } + # Not much we can do if there's no DB. unless ($dbh) { Slim::Utils::Misc::msg("Couldn't connect to info database! Fatal error: [$!] Exiting!\n"); @@ -158,6 +163,15 @@ return $dbh; } +# ping database every once in a while +sub killMorningBug { + my $dbh = shift; + $dbh->ping(); + use Slim::Utils::Timers; + use Time::HiRes; + Slim::Utils::Timers::setTimer($dbh, Time::HiRes::time() + 3 * 60 * 60, \&killMorningBug); +} + sub findUpgrade { my $class = shift; my $currVersion = shift;
Created attachment 478 [details] experimental patch to fix this issue This patch is still not extensively tested but should work though.
For what it's worth, this patch is ineffective on 6.0.2
The Tobias patch works after all! Hooray. My original response refered to Dave Cohen's comment.
OK... The patch prevents the server from crashing while the screensaver is running.. But turn it on or launch the web-interface and crasholla Using 6.1b1: Launching the web-browser: DBD::mysql::st execute failed: MySQL server has gone away at C:\Program Files\SlimServer\server\CPAN/DBIx/ContextualFetch.pm line 51.
Fixed in subversion change 3917.
This bug appears to have been fixed in the latest release! If you are still experiencing this problem, feel free to reopen the bug with your new comments and we'll have another look. Make sure to include the version number of the software you are seeing the error with.