[Slim-Checkins] r11173 - in /branches/6.5/server: Changelog6.html Slim/Buttons/Common.pm Slim/Control/Request.pm Slim/Display/Display.pm Slim/Networking/Select.pm Slim/Utils/Scheduler.pm Slim/Utils/Timers.pm

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Wed Jan 10 14:58:27 PST 2007


Author: adrian
Date: Wed Jan 10 14:58:27 2007
New Revision: 11173

URL: http://svn.slimdevices.com?rev=11173&view=rev
Log:
Bug: 4654
Description: merge 11077, 11078 and 11085 from trunk to harden server
to common crashes by wrapping foreign subroutine execution in evals

Modified:
    branches/6.5/server/Changelog6.html
    branches/6.5/server/Slim/Buttons/Common.pm
    branches/6.5/server/Slim/Control/Request.pm
    branches/6.5/server/Slim/Display/Display.pm
    branches/6.5/server/Slim/Networking/Select.pm
    branches/6.5/server/Slim/Utils/Scheduler.pm
    branches/6.5/server/Slim/Utils/Timers.pm

Modified: branches/6.5/server/Changelog6.html
URL: http://svn.slimdevices.com/branches/6.5/server/Changelog6.html?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Changelog6.html (original)
+++ branches/6.5/server/Changelog6.html Wed Jan 10 14:58:27 2007
@@ -142,6 +142,7 @@
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4600">#4600</a> - Reduce cpu hit of playlist refresh</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4602">#4602</a> - CLI documentation: favorites and live365 errors</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4603">#4603</a> - Genre and Artist missing from song info page</li>
+		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=4654">#4654</a> - harden server to common crashes</li>
 	</ul>
 </ul>
 

Modified: branches/6.5/server/Slim/Buttons/Common.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Buttons/Common.pm?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Slim/Buttons/Common.pm (original)
+++ branches/6.5/server/Slim/Buttons/Common.pm Wed Jan 10 14:58:27 2007
@@ -1571,7 +1571,12 @@
 		my $exitFun = $leaveMode{$oldmode};
 
 		if ($exitFun && ref($exitFun) eq 'CODE') {
-			&$exitFun($client, 'push');
+
+			eval { &$exitFun($client, 'push') };
+
+			if ($@) {
+				msg("Couldn't execute mode exit function: $@\n");
+			}
 		}
 	}
 
@@ -1600,6 +1605,12 @@
 
 	if ($@) {
 		msg("Couldn't push into new mode: [$setmode] !: $@\n");
+
+		pop @{$scrollClientHash->{$client}{scrollParamsStack}};
+		pop @{$client->modeStack};
+		pop @{$client->modeParameterStack};
+
+		return;
 	}
 
 	if ($client->display->hasScreen2) {
@@ -1651,7 +1662,12 @@
 		my $exitFun = $leaveMode{$oldMode};
 
 		if ($exitFun && ref($exitFun) eq 'CODE') {
-			&$exitFun($client, 'pop');
+
+			eval { &$exitFun($client, 'pop') };
+
+			if ($@) {
+				msg("Couldn't execute mode exit function: $@\n");
+			}
 		}
 	}
 	
@@ -1667,7 +1683,11 @@
 
 		my $fun = $modes{$newMode};
 
-		&$fun($client,'pop');
+		eval { &$fun($client,'pop') };
+
+		if ($@) {
+			msg("Couldn't execute setMode on pop: $@\n");
+		}
 	}
 
 	$::d_ui && msg("popped to button mode: " . (mode($client) || 'empty!') . "\n");
@@ -1898,7 +1918,14 @@
 	}
 
 	if ($update2 && (!$display->updateMode || $display->screen2updateOK) && (my $linefunc = $client->lines2periodic()) ) {
-		$client->display->update({ 'screen2' => &$linefunc($client, 1) }, undef, 1);
+
+		my $screen2 = eval { &$linefunc($client, 1) };
+
+		if ($@) {
+			msg("bad screen2 lines: $@\n");
+		}
+
+		$client->display->update({ 'screen2' => $screen2 }, undef, 1);
 	}
 }
 

Modified: branches/6.5/server/Slim/Control/Request.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Control/Request.pm?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Slim/Control/Request.pm (original)
+++ branches/6.5/server/Slim/Control/Request.pm Wed Jan 10 14:58:27 2007
@@ -1642,7 +1642,11 @@
 			
 			$::perfmon && (my $now = Time::HiRes::time());
 		
-			&$notifyFuncRef($self);
+			eval { &$notifyFuncRef($self) };
+
+			if ($@) {
+				msg("Failed notify: $@\n");
+			}
 
 			$::perfmon && $requestTask->log(Time::HiRes::time() - $now) && 
 				msg(sprintf("    Notify: %s\n", Slim::Utils::PerlRunTime::realNameForCodeRef($notifyFuncRef)), undef, 1);

Modified: branches/6.5/server/Slim/Display/Display.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Display/Display.pm?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Slim/Display/Display.pm (original)
+++ branches/6.5/server/Slim/Display/Display.pm Wed Jan 10 14:58:27 2007
@@ -158,7 +158,11 @@
 		$parts = $display->parseLines($lines);
 	} else {
 		my $linefunc = $client->lines();
-		$parts = $display->parseLines(&$linefunc($client));
+		$parts = eval { $display->parseLines(&$linefunc($client)) };
+
+		if ($@) {
+			msg("bad lines function: $@\n");
+		}
 	}
 
 	unless ($s2periodic && $display->screen2updateOK) {
@@ -427,7 +431,11 @@
 	my $linefunc = $client->lines();
 
 	if (defined $linefunc) {
-		return $display->parseLines(&$linefunc($client));
+		my $parts = eval {  $display->parseLines(&$linefunc($client)) };
+		if ($@) {
+			msg("bad lines function: $@\n");
+		}
+		return $parts;
 	} else {
 		return undef;
 	}

Modified: branches/6.5/server/Slim/Networking/Select.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Networking/Select.pm?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Slim/Networking/Select.pm (original)
+++ branches/6.5/server/Slim/Networking/Select.pm Wed Jan 10 14:58:27 2007
@@ -235,7 +235,11 @@
 				# the socket may have passthrough arguments set
 				my $passthrough = ${*$sock}{'passthrough'} || [];
 				
-				$callback->( $sock, @{$passthrough} );
+				eval { $callback->( $sock, @{$passthrough} ) };
+
+				if ($@) {
+					msg("Select task failed: $@\n");
+				}
 
 				$::perfmon && $now && $selectTask->log(Time::HiRes::time() - $now) &&
 					msg(sprintf("    %s\n", Slim::Utils::PerlRunTime::realNameForCodeRef($callback)), undef, 1);

Modified: branches/6.5/server/Slim/Utils/Scheduler.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Utils/Scheduler.pm?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Slim/Utils/Scheduler.pm (original)
+++ branches/6.5/server/Slim/Utils/Scheduler.pm Wed Jan 10 14:58:27 2007
@@ -35,9 +35,7 @@
  your function and a list of arguments. 
 
  Background tasks should be run whenever the server has extra time on its hands, ie,
- when we'd otherwise be sitting in select. To run background tasks, call run_tasks,
- passing as the argument the amount of time (in seconds; 0.1 or less is
- recommended) that you want to spend on them.
+ when we'd otherwise be sitting in select.
 
 =cut
 
@@ -136,7 +134,13 @@
 		my $taskptr = $background_tasks[$curtask];
 		my ($subptr, @subargs) = @$taskptr;
 
-		if (&$subptr(@subargs) == 0) {
+		my $cont = eval { &$subptr(@subargs) };
+
+		if ($@) {
+			msg("Scheduled task failed: $@\n");
+		}
+
+		if ($@ || !$cont) {
 
 			# the task has finished. Remove it from the list.
 			$::d_scheduler && msg("Scheduler: task finished: $subptr\n");

Modified: branches/6.5/server/Slim/Utils/Timers.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Utils/Timers.pm?rev=11173&r1=11172&r2=11173&view=diff
==============================================================================
--- branches/6.5/server/Slim/Utils/Timers.pm (original)
+++ branches/6.5/server/Slim/Utils/Timers.pm Wed Jan 10 14:58:27 2007
@@ -179,9 +179,13 @@
 		$::perfmon && $timerLate->log($now - $timer->{'when'});
 			
 		if ( $subptr ) {
-			$subptr->($objRef, @{$args});
-		}
-		else {
+			eval { $subptr->($objRef, @{$args}) };
+
+			if ($@) {
+				msg("Timer failed: $@\n");
+			}
+
+		} else {
 			msg("Normal timer with no subptr: " . Data::Dump::dump($timer));
 		}
 



More information about the checkins mailing list