Bug 947 - mysql: SlimServer needs to reconnect on lost database connections
: mysql: SlimServer needs to reconnect on lost database connections
Status: CLOSED FIXED
Product: Logitech Media Server
Classification: Unclassified
Component: Database
: 6.0.0
: All All
: P2 enhancement with 2 votes (vote)
: Future
Assigned To: Dan Sully
: mysql
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-03-04 01:22 UTC by Hakan Tandogan
Modified: 2008-12-15 13:06 UTC (History)
3 users (show)

See Also:
Category: ---


Attachments
experimental patch to fix this issue (3.27 KB, patch)
2005-05-01 23:28 UTC, Tobias
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hakan Tandogan 2005-03-04 01:22:45 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.
Comment 1 Dan Sully 2005-03-05 09:23:45 UTC
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.
Comment 2 Dan Sully 2005-03-09 10:55:06 UTC
*** Bug 996 has been marked as a duplicate of this bug. ***
Comment 3 Dan Sully 2005-04-03 11:58:40 UTC
*** Bug 1303 has been marked as a duplicate of this bug. ***
Comment 4 James Craig 2005-04-14 02:19:40 UTC
suggest someone changes the description/keywords to include mysql - that's why
duplicates keep getting resubmitted!
Comment 5 Hakan Tandogan 2005-04-14 02:49:14 UTC
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.
Comment 6 Dave Cohen 2005-04-14 10:17:16 UTC
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;







Comment 7 Tobias 2005-05-01 23:28:17 UTC
Created attachment 478 [details]
experimental patch to fix this issue

This patch is still not extensively tested but should work though.
Comment 8 Brad Kent 2005-06-20 07:11:27 UTC
For what it's worth, this patch is ineffective on 6.0.2
Comment 9 Brad Kent 2005-06-30 19:53:05 UTC
The Tobias patch works after all!   Hooray.
My original response refered to Dave Cohen's comment.
Comment 10 Brad Kent 2005-07-09 09:41:56 UTC
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.
Comment 11 Dan Sully 2005-08-09 17:46:55 UTC
Fixed in subversion change 3917.
Comment 12 James Richardson 2008-12-15 13:06:13 UTC
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.