Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zargs with -P intermittently failing in zsh 5.9 and macOS



> 2022/05/25 2:32, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 
>> +(eval):6> case 19 (<1-125>|128)
>> +(eval):8> ret=123
>> 
>> at least once, even though f always returned 0.
> 
> Something is causing the subshell that was running f to exit with
> status 19 even though f returned 0.

The problem can be reproduced by the following simplified script:

#!/bin/zsh
_zajobs=()
(   # works OK if not run in a subshell
    np=10   # try increasing this if you do not get $? = 19
    for ((i=0; i<$np; ++i)); do
        curl -so /dev/null 'https://example.com' & _zajobs+=( $! )
    done

    #sleep 1    # works OK if 'sleep 1' is added here
    wait        # works OK if this line is commented out
    for p in $_zajobs; do
        wait $p
        echo $p $?
    done
)

If I run this script on my Mac, a few (one or two in most cases, zero or
three sometimes) of the ten "wait $p" give $? = 19.

But all the "wait $p" return 0 if
(1) remove the "wait" before the "for p in $_zajobs", or
(2) add "sleep 1" before the "wait", or
(3) run whole script in the main shell, i.e., remove the enclosing
"(" and ")", or
(4) replace "curl -so /dev/null 'https://example.com'" by "sleep 1",
or
(5) run the script on Linux (I haven't tried other BSDs).

(1)(2) may indicate that the first "wait" (without $p) can't correctly
wait for some of the child procs...?




Messages sorted by: Reverse Date, Date, Thread, Author