From 28802c83aadc4572181c628a193b5819604ec243 Mon Sep 17 00:00:00 2001 From: Sam Vilain Date: Tue, 8 Nov 2011 16:02:33 -0800 Subject: [PATCH] Avoid an undef method exception If the _get_js_sock function returns undef, it is placed into the loaned_sock property inside _get_loaned_sock. This can cause 'Can't call method "close" on an undefined value' later on; so, don't put undef in there, and don't die when the value is undef. --- lib/Gearman/Taskset.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Gearman/Taskset.pm b/lib/Gearman/Taskset.pm index e7bdd1b..bc33f6a 100644 --- a/lib/Gearman/Taskset.pm +++ b/lib/Gearman/Taskset.pm @@ -85,7 +85,7 @@ sub cancel { } while (my ($hp, $sock) = each %{ $ts->{loaned_sock} }) { - $sock->close; + $sock->close if $sock; } $ts->{waiting} = {}; @@ -102,7 +102,10 @@ sub _get_loaned_sock { } my $sock = $ts->{client}->_get_js_sock($hostport); - return $ts->{loaned_sock}{$hostport} = $sock; + if ($sock) { + $ts->{loaned_sock}{$hostport} = $sock; + } + return $sock; } # event loop for reading in replies