Homebrew / homebrew-core

🍻 Default formulae for the missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
13.77k stars 12.45k forks source link

zargs in zsh 5.9 intermittently failing #101937

Closed ericbn closed 2 years ago

ericbn commented 2 years ago

brew gist-logs <formula> link OR brew config AND brew doctor output

$ brew config
HOMEBREW_VERSION: 3.4.11-72-g5d4353f
ORIGIN: https://github.com/Homebrew/brew
HEAD: 5d4353f617fa2aa684582aa868c2e5016d8987b5
Last commit: 21 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 2e83ac65bb2008f4c54a6464084f6a2fa9641af0
Core tap last commit: 6 hours ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://github.com/Homebrew/homebrew-core
HOMEBREW_EDITOR: vim
HOMEBREW_MAKE_JOBS: 8
HOMEBREW_NO_ANALYTICS: set
Homebrew Ruby: 2.6.8 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit haswell
Clang: 13.1.6 build 1316
Git: 2.32.1 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 7.79.1 => /usr/bin/curl
macOS: 12.4-x86_64
CLT: 13.4.0.0.1.1651278267
Xcode: N/A

$ brew doctor
Your system is ready to brew.

Verification

What were you trying to do (and why)?

Minimal reproducible example:

$ f() { curl -Sso /dev/null 'https://example.com'; return 0 }
$ autoload -Uz zargs
$ zargs -n 1 -P 0 -- {1..13} -- f
$ print ${?}

A more complete reproducible example, which is the one that got our attention:

$ cd ${$(mktemp -d):A}
$ touch .zshrc
$ ZDOTDIR=${PWD} HOME=${PWD} ZIM_HOME=${PWD}/.zim exec zsh
$ curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh

This was first reported in https://github.com/zimfw/zimfw/discussions/459

This is not reproducible with earlier versions of Zsh installed via Homebrew, or with the /bin/zsh bundled with macOS (Zsh version 5.8.1 in macOS 12.4).

Also, this is not reproducible with the zsh-users docker image:

$ docker run --rm -it zshusers/zsh:5.9
$ apt update
$ apt install -y curl git
$ f() { curl -Sso /dev/null 'https://example.com'; return 0 }
$ autoload -Uz zargs
$ zargs -n 1 -P 0 -- {1..13} -- f
$ print ${?}
0
$ curl -fsSL https://raw.githubusercontent.com/zimfw/install/master/install.zsh | zsh
) Using Zsh version 5.9
) ZIM_HOME not set, using the default one.
) Changed your default shell to /usr/bin/zsh
) Downloaded the Zim script to /root/.zim/zimfw.zsh
) Prepended Zim template to /root/.zimrc
) Prepended Zim template to /root/.zshrc
) Installed modules.
All done. Enjoy your Zsh IMproved! Restart your terminal for changes to take effect.

What happened (include all command output)?

In the first example, the output was:

123

If the f function is simplified, I don't see the error. Not sure if it's related to network activity. Added the extra return 0 in the f function to force that return code. If the -P 0 is removed, I don't see the error. So looks like it's related to concurrency. If the range is shortened, the error will be less frequent. Even with {1..13} it happens to sometimes succeed in my Mid 2015 2.2 GHz Quad-Core Intel Core i7.

In the second example, the output was:

) Using Zsh version 5.9
) Your ZIM_HOME is the default one.
) Zsh is your default shell.
) Downloaded the Zim script to /.../.zim/zimfw.zsh
) Prepended Zim template to /.../.zimrc
) Prepended Zim template to /.../.zshrc

x Could not install modules.

Sometimes it might succeed. In this case, repeat the example a couple of more times.

What did you expect to happen?

In the first example, I expected:

0

since the return from all executions of f was 0.

In the second example, I expected a different message at the end:

) Installed modules.
All done. Enjoy your Zsh IMproved! Restart your terminal for changes to take effect.

Step-by-step reproduction instructions (by running brew commands)

$ brew install zsh
$ chsh -s /usr/local/bin/zsh
$ # Restart your terminal and follow the examples above
SMillerDev commented 2 years ago

Have you tried compiling zsh outside of homebrew to validate if it's a homebrew issue?

carlocab commented 2 years ago

It works in the Docker container. However, it could also be a bug that affects only macOS builds.

alebcay commented 2 years ago

My hunch so far is that this is a macOS build issue. I can't reproduce the issue in the Homebrew container using brewed zsh.

I was able to reproduce the issue with a copy of zsh compiled locally in two instances on macOS Monterey, with the following two sets of arguments at configure time (second time was to verify that Homebrew-passed arguments would not be a likely culprit):

./configure --prefix=$(pwd)/out --enable-fndir=$(pwd)/aux/functions \
  --enable-scriptdir=$(pwd)/aux/scripts --enable-site-fndir=$(pwd)/out/aux/site-functions \
  --enable-site-scriptdir=$(pwd)/out/aux/site-scripts --enable-runhelpdir=$(pwd)/aux/help \
  --enable-cap --enable-maildir-support --enable-multibyte --enable-pcre --enable-zsh-secure-free \
  --enable-unicode9 --enable-etcdir=/etc --with-tcsetpgrp DL_EXT=bundle
./configure --prefix=$(pwd)/out --enable-fndir=$(pwd)/share/functions \
  --enable-scriptdir=$(pwd)/share/scripts --enable-site-fndir=$(pwd)/out/share/site-functions \
  --enable-site-scriptdir=$(pwd)/out/share/site-scripts --enable-runhelpdir=$(pwd)/share/help

Still trying to fire up MacPorts on a VM to see if their copy exhibits the same issue.

alebcay commented 2 years ago

Reproduced the same issue in zsh 5.9 from MacPorts.

ismail commented 2 years ago

I suggest reporting the bug to zsh-workers mailing list: https://www.zsh.org/mla/

ericbn commented 2 years ago

Reported it to zsh-workers here: https://www.zsh.org/mla/workers/2022/msg00611.html

carlocab commented 2 years ago

There's nothing actionable here for now (for Homebrew, anyway), so I'm closing this.

Feel free to open a new issue (or, better, a pull request) if there are any developments that we can do something about.

ericbn commented 2 years ago

This was fixed by @Jun-T in patch 50306 in zsh.

carlocab commented 2 years ago

Feel free to open a PR to apply the patch in the zsh formula.