diff --git a/bin/pt-kill b/bin/pt-kill index 7155f011..e54de355 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -2177,6 +2177,7 @@ sub find { } if ( $find_spec{busy_time} && ($query->{Command} || '') eq 'Query' ) { + next QUERY unless defined $query->{Time}; if ( $query->{Time} < $find_spec{busy_time} ) { PTDEBUG && _d("Query isn't running long enough"); next QUERY; @@ -2186,6 +2187,7 @@ sub find { } if ( $find_spec{idle_time} && ($query->{Command} || '') eq 'Sleep' ) { + next QUERY unless defined $query->{Time}; if ( $query->{Time} < $find_spec{idle_time} ) { PTDEBUG && _d("Query isn't idle long enough"); next QUERY; diff --git a/lib/Processlist.pm b/lib/Processlist.pm index 092f3589..a4c40d3c 100644 --- a/lib/Processlist.pm +++ b/lib/Processlist.pm @@ -470,6 +470,7 @@ sub find { # Match special busy_time. if ( $find_spec{busy_time} && ($query->{Command} || '') eq 'Query' ) { + next QUERY unless defined($query->{Time}); if ( $query->{Time} < $find_spec{busy_time} ) { PTDEBUG && _d("Query isn't running long enough"); next QUERY; @@ -480,6 +481,7 @@ sub find { # Match special idle_time. if ( $find_spec{idle_time} && ($query->{Command} || '') eq 'Sleep' ) { + next QUERY unless defined($query->{Time}); if ( $query->{Time} < $find_spec{idle_time} ) { PTDEBUG && _d("Query isn't idle long enough"); next QUERY; diff --git a/t/lib/Processlist.t b/t/lib/Processlist.t index e82c0c53..75debb8e 100644 --- a/t/lib/Processlist.t +++ b/t/lib/Processlist.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 32; +use Test::More tests => 34; use Processlist; use PerconaTest; @@ -827,6 +827,37 @@ is_deeply( "Find all queries that aren't ignored" ); +# ############################################################################# +# https://bugs.launchpad.net/percona-toolkit/+bug/923896 +# ############################################################################# + +%find_spec = ( + busy_time => 1, + ignore => {}, + match => {}, +); +my $proc = { 'Time' => undef, + 'Command' => 'Query', + 'db' => undef, + 'Id' => '7', + 'Info' => undef, + 'User' => 'msandbox', + 'State' => '', + 'Host' => 'localhost' + }; + +local $@; +eval { $pl->find([$proc], %find_spec) }; +ok !$@; + +delete $find_spec{busy_time}; +$find_spec{idle_time} = 1; +$proc->{Command} = 'Sleep'; + +local $@; +eval { $pl->find([$proc], %find_spec) }; +ok !$@; + # ############################################################################# # Done. # #############################################################################