bugGNU Parallel - Bugs: bug #52207, Exit status 0 when child job is...

 
 

bug #52207: Exit status 0 when child job is killed, even with "now,fail=1"

Submitter:  None
Submitted:  Wed 11 Oct 2017 03:13:54 PM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Fixed
Privacy:  Public Assigned to:  tange
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 06 Jan 2018 07:00:06 PM UTC, comment #4: 

Fixed in [a048f547].

Ole Tange <tange>
Group administrator
Fri 27 Oct 2017 09:48:22 PM UTC, comment #3: 

I can confirm your bug report. Thanks for that.

However, the change you suggest seems to force a normal job to have exit status 128. That is no good.

I have looked further into your problem. Here is a workaround:

(sleep 5 && killall sleep) &
parallel --halt-on-error now,fail=1 'true;sleep' ::: 10; echo $?

So why does 'sleep 10' do the wrong thing, while 'true;sleep 10' does the right thing?

https://unix.stackexchange.com/questions/400971/perl-error-code-returned-to-open3-after-killed-program

Ole Tange <tange>
Group administrator
Wed 11 Oct 2017 08:28:05 PM UTC, comment #2: 

I did some debugging, and here's what I think is going on.

[parallel, line 9074]
$Global::halt_exitstatus = $job->exitstatus();

Killed jobs have exit status 0 but carry a separate exitsignal. This is why the ultimate exit status is 0.

I propose the following change:
$Global::halt_exitstatus = $job->exitstatus() != 0 ? $job->exitstatus() : $job->exitsignal() + 128;

It uses the exit status if it's meaningful, or it falls back to using the exitsignal information.

It seems the convention is for a killed process to exit with the signal + 128, so that's the purpose of the math above.

Would you agree that we should fail if a child process is killed? How does this solution look to you?

Thanks!

Jared R. White <jaredwhite128>
Wed 11 Oct 2017 06:56:19 PM UTC, comment #1: 

I made an error in my original submission. It should have read:

# wrapping my job in bash changes nothing
$ (sleep 5 && killall sleep) &
$ bash -c "sleep 10" || echo "failed as expected"
Terminated
failed as expected

Sorry about that.

Jared R. White <jaredwhite128>
Wed 11 Oct 2017 03:13:54 PM UTC, original submission:  

The parallel processes I'm coordinating need simple, bulletproof exit status propagation – so naturally I went to GNU Parallel and am testing various edge cases.

I'm using "--halt-on-exit now,fail=1"

Jobs failing naturally result in behavior as described in the manual:
"If fail=1 is used, the exit status will be the exit status of the failing job."

However, if a child process is killed separately ("kill $pid"), then parallel exits 0, which seems unexpected.

###

First, a demo that killing delivers a non-zero exit status:

# delayed kill, a placeholder for someone killing
$ (sleep 5 && killall sleep) &
$ sleep 10; echo $?
Terminated
143

# bash can behave based on that exit status
$ (sleep 5 && killall sleep) &
$ sleep 10 || echo "failed as expected"
Terminated
failed as expected

# wrapping my job in bash changes nothing
$ (sleep 5 && killall sleep) &
$ bash -c "sleep 10" || echo "failed as expected"

###

Now we involve parallel to show the unexpected behavior:

$ cat jobs.txt
echo hello
uptime
date
sleep 10

$ (sleep 5 && killall sleep) &

$ parallel --will-cite --halt-on-error now,fail=1 --jobs 0 < jobs.txt
hello
Wed Oct 11 11:08:13 EDT 2017
 11:08:13 up 64 days, 16:53, 107 users,  load average: 2.38, 2.55, 2.57
parallel: This job failed:
sleep 10

$ echo $?
0

###

Parallel does behave properly when the failure happens naturally:

$ cat jobs.txt
foo
bar

$ parallel --will-cite --halt-on-error now,fail=1 --jobs 0 < jobs.txt
/bin/bash: foo: command not found
parallel: This job failed:
foo
/bin/bash: bar: command not found
parallel: This job failed:
bar

$ echo $?
127

###

$ parallel --version
GNU parallel 20170922

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by tange (Posted a comment)
  • -email is unavailable- added by jaredwhite128 (Posted a comment)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-01-06 tange StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2017-10-27 tange StatusNone Confirmed
        Assigned toNone tange

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code