From f9d868590efb81cee078d19d3be91ef297634499 Mon Sep 17 00:00:00 2001 From: Tom Clegg Date: Fri, 22 Jan 2016 15:02:21 -0500 Subject: [PATCH] 7263: Avoid getting stuck processing stderr for one task for a long time. Do not sleep(0.1) unless pipes are idle. --- sdk/cli/bin/crunch-job | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/sdk/cli/bin/crunch-job b/sdk/cli/bin/crunch-job index 70d05f023c..f83e7babac 100755 --- a/sdk/cli/bin/crunch-job +++ b/sdk/cli/bin/crunch-job @@ -1057,12 +1057,14 @@ for (my $todo_ptr = 0; $todo_ptr <= $#jobstep_todo; $todo_ptr ++) check_refresh_wanted(); check_squeue(); update_progress_stats(); - select (undef, undef, undef, 0.1); } elsif (time - $progress_stats_updated >= 30 || $progress_is_dirty) { update_progress_stats(); } + if (!$gotsome) { + select (undef, undef, undef, 0.1); + } $working_slot_count = scalar(grep { $_->{node}->{fail_count} == 0 && $_->{node}->{hold_count} < 4 } @slot); if (($thisround_failed_multiple >= 8 && $thisround_succeeded == 0) || @@ -1432,15 +1434,21 @@ sub readfrompipes foreach my $job (keys %reader) { my $buf; - while (0 < sysread ($reader{$job}, $buf, 8192)) + if (0 < sysread ($reader{$job}, $buf, 65536)) { print STDERR $buf if $ENV{CRUNCH_DEBUG}; $jobstep[$job]->{stderr_at} = time; $jobstep[$job]->{stderr} .= $buf; + + # Consume everything up to the last \n preprocess_stderr ($job); + if (length ($jobstep[$job]->{stderr}) > 16384) { - substr ($jobstep[$job]->{stderr}, 0, 8192) = ""; + # If we get a lot of stderr without a newline, chop off the + # front to avoid letting our buffer grow indefinitely. + substr ($jobstep[$job]->{stderr}, + 0, length($jobstep[$job]->{stderr}) - 8192) = ""; } $gotsome = 1; } -- 2.30.2