tokuhirom / plenv

Perl binary manager
Other
512 stars 70 forks source link

bash fork error #120

Closed abra closed 8 years ago

abra commented 8 years ago

After adding these two lines in .bash_profile

export PATH="$HOME/.plenv/bin:$PATH"
eval "$(plenv init -)"

I got messages bash: fork: retry: No child processes and bash: fork: Resource temporarily unavailable in terminal when trying open new tab in iterm2 with bash or run any other command line tools, but these messages keep showing up every time.

screen shot 2016-01-26 at 21 06 24 screen shot 2016-01-26 at 20 07 32 screen shot 2016-01-26 at 21 17 16

OS: OS X 10.11 El Capitan Bash version: 4.3.42

miyagawa commented 8 years ago

Are you using the latest plenv?

Previous versions of plenv had issues with perl executable commands in your PATH such as perl power tools because it recursively forks plenv commands.

abra commented 8 years ago

Yes, I'm using latest version 2.2.0.

miyagawa commented 8 years ago

You're likely to have a perl-based command such as head in your PATH that is causing the recursive fork. ls ~/.plenv/shims and you'll see some fishy executable there.

abra commented 8 years ago

I don't see any files in ~/.plenv/shims, it's empty.

miyagawa commented 8 years ago

So where exactly is ls though? which ls should show it.

abra commented 8 years ago
/bin/ls
miyagawa commented 8 years ago

if you run /bin/ls do you see the error? I doubt that ls is actually causing the error.

abra commented 8 years ago

Yes, when I run /bin/ls I see message bash: fork: retry: No child processes screen shot 2016-01-26 at 23 33 23

miyagawa commented 8 years ago

I think your system is horsed already and anything that involves fork will see that error, regardless of whether it uses plenv or not.

miyagawa commented 8 years ago

I'm sure this issue has been solved in the latest git of plenv. Don't you have perl power tools or some CLI command line installed using perl? Otherwise all I can suggest is to remove ~/.plenv and start over.

abra commented 8 years ago

When I comment lines export PATH="$HOME/.plenv/bin:$PATH" and eval "$(plenv init -)" and re-run bash, error doesn't appear.

miyagawa commented 8 years ago

How did you install plenv? If you're not using git, does installing from git help? If you're using git, which commit hash are you at? git rev-parse HEAD. If you're on the latest, does checking out old releases fix the issue?

abra commented 8 years ago

My steps to install plenv:

  1. git clone https://github.com/tokuhirom/plenv.git ~/.plenv
  2. echo 'export PATH="$HOME/.plenv/bin:$PATH"' >> ~/.bash_profile
  3. echo 'eval "$(plenv init -)"' >> ~/.bash_profile
  4. exec $SHELL -l and after last step I got error message in terminal when tried to run cd/ls/tree/etc
miyagawa commented 8 years ago

Can you try older release using this method to checkout specific tag or commit in git? https://github.com/tokuhirom/plenv#upgrading

abra commented 8 years ago

I checked (not every) commit up to 26dbef7 and still get error messages. I think something wrong with my environment, but I have no idea why.

syohex commented 8 years ago

@abra Could you show us ulimit -a ? Did you set too small value to processes parameter ?

miyagawa commented 8 years ago

@abra If you just do:

export PATH="$HOME/.plenv/bin:$PATH"
bash -x $(which plenv) init  -

what does it show? I wonder if it might show some infinite loops there.

abra commented 8 years ago

ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
file size               (blocks, -f) unlimited
max locked memory       (kbytes, -l) unlimited
max memory size         (kbytes, -m) unlimited
open files                      (-n) 256
pipe size            (512 bytes, -p) 1
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 709
virtual memory          (kbytes, -v) unlimited
abra commented 8 years ago
[~] ··············································· [27/01/16 07:47:43]
→ export PATH="$HOME/.plenv/bin:$PATH"
[~] ··············································· [27/01/16 07:48:43]
→ bash -x $(which plenv) init  -
+ set -e
+ export -n CDPATH
+ '[' init = --debug ']'
+ '[' -n '' ']'
+ read READLINK
++ type -p greadlink readlink
+ export READLINK
+ '[' -z '' ']'
+ PLENV_ROOT=/Users/abra/.plenv
+ export PLENV_ROOT
+ '[' -z '' ']'
+ PLENV_DIR=/Users/abra
+ export PLENV_DIR
+ shopt -s nullglob
++ abs_dirname /Users/abra/.plenv/bin/plenv
++ local cwd=/Users/abra
++ local path=/Users/abra/.plenv/bin/plenv
++ '[' -n /Users/abra/.plenv/bin/plenv ']'
++ cd /Users/abra/.plenv/bin
++ local name=plenv
+++ /opt/local/bin/greadlink plenv
++ path=../libexec/plenv
++ '[' -n ../libexec/plenv ']'
++ cd ../libexec
++ local name=plenv
+++ /opt/local/bin/greadlink plenv
+++ true
++ path=
++ '[' -n '' ']'
++ pwd
++ cd /Users/abra
+ bin_path=/Users/abra/.plenv/libexec
+ for plugin_bin in '"${PLENV_ROOT}/plugins/"*/bin'
+ bin_path=/Users/abra/.plenv/libexec:/Users/abra/.plenv/plugins/perl-build/bin
+ export PATH=/Users/abra/.plenv/libexec:/Users/abra/.plenv/plugins/perl-build/bin:/Users/abra/.plenv/bin:/Users/abra/.cargo/bin:/Users/abra/.go/bin:/opt/vert.x-3.2.0-full/bin:/opt/apache-maven-3.3.9/bin:/Users/abra/android_sdk/tools:/Users/abra/android_sdk/platform-tools:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
+ PATH=/Users/abra/.plenv/libexec:/Users/abra/.plenv/plugins/perl-build/bin:/Users/abra/.plenv/bin:/Users/abra/.cargo/bin:/Users/abra/.go/bin:/opt/vert.x-3.2.0-full/bin:/opt/apache-maven-3.3.9/bin:/Users/abra/android_sdk/tools:/Users/abra/android_sdk/platform-tools:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin
+ hook_path=:/Users/abra/.plenv/plenv.d:/usr/local/etc/plenv.d:/etc/plenv.d:/usr/lib/plenv/hooks
+ export PLENV_HOOK_PATH=:/Users/abra/.plenv/plenv.d:/usr/local/etc/plenv.d:/etc/plenv.d:/usr/lib/plenv/hooks
+ PLENV_HOOK_PATH=:/Users/abra/.plenv/plenv.d:/usr/local/etc/plenv.d:/etc/plenv.d:/usr/lib/plenv/hooks
+ shopt -u nullglob
+ command=init
+ case "$command" in
++ command -v plenv-init
+ command_path=/Users/abra/.plenv/libexec/plenv-init
+ '[' -z /Users/abra/.plenv/libexec/plenv-init ']'
+ shift 1
+ exec /Users/abra/.plenv/libexec/plenv-init -
export PATH="/Users/abra/.plenv/shims:${PATH}"
export PLENV_SHELL=bash
source '/Users/abra/.plenv/libexec/../completions/plenv.bash'

plenv() {
  local command

  command="$1"
  if [ "$#" -gt 0 ]; then
    shift
  fi

  case "$command" in
  rehash|shell)
    eval "`plenv "sh-$command" "$@"`";;
  *)
    command plenv "$command" "$@";;
  esac
}
miyagawa commented 8 years ago

@abra so ok - plenv init - won't cause any loops? When you eval it it happens? Can you trace that?

syohex commented 8 years ago

Your processes limit has no problem.

Can you reproduce without eval, to execute commands step by step or to load it from file(% plenv init - > plenv_init && source plenv_init)?

abra commented 8 years ago

I load file as you suggest ~/.plenv/bin/plenv init - > plenv_init && source plenv_init, then I export path export PATH="$HOME/.plenv/bin:$PATH" and exec $SHELL -l, after all I run command line tools ls/tree/etc.. as usual and they work without any error messages.

syohex commented 8 years ago

Did you use plenv in such case ?

And do you set any alias of eval or define eval function ?

abra commented 8 years ago

When I loaded file plen_init, I didn't use plenv. I don't use eval in my alias or functions. % type eval eval is a shell builtin

my .bash_profile:

# Locales
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

# Detect OS
# OS=$(uname -s)

# Don't put duplicate lines in the history.
# See bash(1) for more options ... or force ignoredups and ignorespace
# HISTCONTROL=ignoredups:ignorespace
HISTCONTROL=ignoredups:erasedups

# Check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# Append to the history file, don't overwrite it
shopt -s histappend

# For setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=
HISTFILESIZE=
HISTTIMEFORMAT="[%d/%m/%y %T] "
HISTFILE=~/.bash_eternal_history

# Bash prompt settings
NCY="\[\033[0;36m\]" # CYAN
LCY="\[\033[1;36m\]" # LIGHT CYAN
NGR="\[\033[0;32m\]" # GREEN
LGR="\[\033[1;32m\]" # LIGHT GREEN
NRD="\[\033[0;31m\]" # RED
LRD="\[\033[1;31m\]" # LIGHT RED
NBK="\[\033[0;30m\]" # BLACK
LBK="\[\033[1;30m\]" # LIGHT BLACK
NWT="\[\033[0;37m\]" # WHITE
LWT="\[\033[1;37m\]" # LIGHT WHITE
NYL="\[\033[0;33m\]" # YELLOW
LYL="\[\033[1;33m\]" # LIGHT YELLOW
NBL="\[\033[0;34m\]" # BLUE
LBL="\[\033[1;34m\]" # LIGHT BLUE
DFT="\[\033[0;39m\]" # DEFAULT
LDT="\[\033[1;39m\]" # LIGHT DEFAULT
NC="\[\033[0m\]"

#PS1="$LBK[ $NCY\u$LBK ] $NCY>$NC "
PS_LINE=`printf -- '·%.0s' {1..200}`

function __parse_git_branch() {
    PS_BRANCH=''

    GREEN="$(echo -e "\033[0;32m")"
    YELLOW="$(echo -e "\033[0;33m")"
    BLACK="$(echo -e "\033[1;30m")"
    RESET="$(echo -e "\033[0m")"

    DATE="$(date +"%d/%m/%y %T")"
    PS_FILL=${PS_LINE:0:$COLUMNS}
    # if [ -d .svn ]; then {{{
    #     PS_BRANCH="(svn: r$(svn info|awk '/Revision/{print $2}'))"
    #     return
    # elif [ -f _FOSSIL_ -o -f .fslckout ]; then
    #     PS_BRANCH="(fossil: $(fossil status|awk '/tags/{print $2}')) "
    #     return
    # fi }}}
    ref=$(git symbolic-ref HEAD 2> /dev/null) || return
    BRANCH=$'\u2387 '
    PS_BRANCH="$BLACK($YELLOW$BRANCH ${ref#refs/heads/}$BLACK)$RESET "
}

export PROMPT_COMMAND=__parse_git_branch
PS_INFO="$LBK[$NBL\w$LBK]$NC"
PS_GIT="$NYL\$PS_BRANCH$NC"
PS_TIME="\[\033[\$((COLUMNS-19))G\] $LBK[$NGR\$DATE$LBK]"
ARW="$NGR\342\206\222 $NC"
export PS1="$LBK\${PS_FILL}\[\033[0G\]${PS_INFO} ${PS_GIT}${PS_TIME}\n$ARW"

# Only show the current directory's name in the tab
# if [ $ITERM_SESSION_ID ]; then
#     export PROMPT_COMMAND="echo -ne '\033]0;${PWD##*/}\007'; $PROMPT_COMMAND"
# fi

# Save and reload the history after each command finishes
# export PROMPT_COMMAND="history -n; history -a; history -c; history -r; $PROMPT_COMMAND"
export PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

# Dir colors
if [ "$TERM" != "dumb" ]; then
    export LS_OPTIONS='--color=auto'
    export CLICOLOR=1
fi

# Terminal colors
export CLICOLOR=1
export LSCOLORS=exfxcxdxcxegedabagacad

# Grep highlight color
export GREP_COLOR='0;33;40'

# Aliases
alias c='clear'
alias tree='tree -C -N'
alias now='date +"%T"'
alias dt='date "+%F %T"'
alias ll='ls -lFh'
alias llt='ll -t'
alias ltl='llt | less'
alias lla='ls -laFh'
alias la='ls -A'
alias l='ls -CF'
alias lls='ll -S'
alias lhd='lla -d .??*'
alias df='df -H'
alias du='du -sh'
alias rm='rm -v'
alias h='history'
alias e='exit'
alias grep='grep --color=auto'
alias unigrep='grep -P "[^\x00-\x7F]"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias lsl="ls -lhFA | less"
alias ..='cd ../'
alias ...='cd ../../'
alias ....='cd ../../../'
alias .....='cd ../../../../'
# Vagrant
alias vup="vagrant up"
alias vhalt="vagrant halt"
alias vs="vagrant suspend"
alias vr="vagrant resume"
alias vrld="vagrant reload"
alias vssh="vagrant ssh"
alias vstat="vagrant status"

# Show ip address
if [ -f $(which curl) ]; then
    alias myip='curl http://ifconfig.co'
fi

# alias for Mac OS X
alias m='open -a MacVim'
alias chrome="open -a Google\ Chrome"
# alias adobe="open -a Adobe\ Reader"
alias firefox="open -a Firefox"
alias vlc="open -a vlc"
alias xee="open -a Xee³"
alias f="open -a Finder $PWD"

# Bash completion
if [ -f /opt/local/etc/profile.d/bash_completion.sh ]; then
    . /opt/local/etc/profile.d/bash_completion.sh
fi

# Where/What is this binary? Shows extended ls output
wtf () {
    which $1 | xargs ls -la
}

# Print working directory {{{
# [01/03/15 00:23:37] -> /Users/user after a cd
# cd () {
#     if [[ $@ == '-' ]]; then
#         builtin cd "$@" > /dev/null # We'll handle pwd.
#     else
#         builtin cd "$@"
#     fi
#         echo -e "\033[1;30m"[$(date +"%d/%m/%y %T")] \-\> "\033[0;33m"`pwd`"\033[0m"
# }
# }}}

# Create directory and browse to it
mcd () {
    mkdir -p "$@" && cd "$@"
}

# Open man page as PDF
function manpdf() {
    man -t "${1}" | open -f -a /Applications/Preview.app/
}

# Shows bitrate of mp3 file
bitrate () {
    echo `basename "$1"`: `file "$1" | sed 's/.*, \(.*\)kbps.*/\1/' | tr -d " " ` kbps
}

# Extract most know archives with one command
# usage: extract filename.zip
extract () {
    if [ -f $1 ]; then
        case $1 in
            *.tar.bz2) tar xjvf $1           ;;
            *.tar.gz)  tar xzvf $1           ;;
            *.bz2)     bzcat $1 > ${1%.bz2}  ;;
            *.rar)     unrar x $1            ;;
            *.gz)      zcat $1 > ${1%.gz}    ;;
            *.tar)     tar xvf $1            ;;
            *.tbz2)    tar xjvf $1           ;;
            *.tgz)     tar xzvf $1           ;;
            *.zip)     unzip $1              ;;
            *.rar)     unrar x $1            ;;
            *.Z)       uncompress $1         ;;
            *.7z)      7z x $1               ;;
            *.xz)      xz -d -v $1           ;;
            *.tbz)     tar xjvf              ;;
            *) echo "Unable to extract '$1'" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

# Compress files with one command
# usage: compress zip filename
compress () {
    if [ $1 ]; then
        case $1 in
            tbz)    tar cjvf $2.tar.bz2 $2    ;;
            tgz)    tar czvf $2.tar.gz $2     ;;
            tar)    tar cpvf $2.tar $2        ;;
            bz2)    bzip2 -9 $2               ;;
            gz)     gzip -c -9 -n $2 > $2.gz  ;;
            zip)    zip -r $2.zip $2          ;;
            rar)    rar a -m5 $2.rar $2       ;;
            7z)     7z a -mx=9 $2.7z $2       ;;
            xz)     xz -z -9 -v $2            ;;
            *) echo "Unable to compress '$1'" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}

# Color man output
man() {
    env LESS_TERMCAP_mb=$(printf "\e[1;31m") \
    LESS_TERMCAP_md=$(printf "\e[0;33m") \
    LESS_TERMCAP_me=$(printf "\e[0m") \
    LESS_TERMCAP_se=$(printf "\e[0m") \
    LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
    LESS_TERMCAP_ue=$(printf "\e[0m") \
    LESS_TERMCAP_us=$(printf "\e[0;32m") \
    man "$@"
}

# Man pages in vim {{{
# vman() {
#     vim -c "SuperMan $*"
#
#     if [ "$?" != "0" ]; then
#         echo "No manual entry for $*"
#     fi
# }
# }}}

# MacPorts
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

# Android SDK tools
export PATH=/Users/abra/android_sdk/platform-tools:$PATH
export PATH=/Users/abra/android_sdk/tools:$PATH

# MySQL
# export PATH=/opt/local/lib/mysql56/bin:$PATH

# Postgres
# export POSTGRES_HOME=/opt/local/lib/postgresql94/

# Java
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_72.jdk/Contents/Home"

# Maven
export PATH=/opt/apache-maven-3.3.9/bin:$PATH

# Vert.x 3
export PATH=/opt/vert.x-3.2.0-full/bin:$PATH

# Brew completion {{{
# if [ -f /path/to/brew-completion.sh ]; then
#    . /path/to/brew-completion.sh
# fi
# }}}

# Go lang
export GOPATH=$HOME/.go
export PATH=$GOPATH/bin:$PATH

# Rust
export PATH=$HOME/.cargo/bin:$PATH

# plenv
#export PATH="$HOME/.plenv/bin:$PATH"
#eval "$(plenv init -)"
syohex commented 8 years ago

Hmm, I cannot reproduce this issue with your .bash_profile(comment out plenv lines) on MacOSX bash 3.2.57.

syohex commented 8 years ago

I cannot reproduce this issue with it on Ubuntu bash 4.3.42 too.

abra commented 8 years ago

Something wrong with my vim, check out this video I recorded https://www.dropbox.com/s/3422zvsdvh3h0b2/bash_fork.mov?dl=0 Just noticed that vim causes the problem.

abra commented 8 years ago

Everything works fine until I run vim or macvim.

abra commented 8 years ago

I think I found the problem, these lines in my .vimrc somehow recursively fork plenv command

" ⌘ Q when :qa in MacVim
if has("unix")
    let s:uname = system("uname -s")
    if s:uname == "Darwin"
        autocmd VimLeave * macaction terminate:
    endif
endif

I removed them and everything works fine now.

syohex commented 8 years ago

Thanks for information. I'll try to reproduce and try to fix if feasible.

abra commented 8 years ago

I found one more cause of the problem in file ~/.vim/bundle/vim-perl/ftplubin/perl.vim when try open perl files:

" Set this once, globally.
if !exists("perlpath")
    if executable("perl")
      try
    if &shellxquote != '"'
        let perlpath = system('perl -e "print join(q/,/,@INC)"')
    else
        let perlpath = system("perl -e 'print join(q/,/,@INC)'")
    endif
    let perlpath = substitute(perlpath,',.$',',,','')
      catch /E145:/
    let perlpath = ".,,"
      endtry
    else
    " If we can't call perl to get its path, just default to using the
    " current directory and the directory of the current file.
    let perlpath = ".,,"
    endif
endif

screen shot 2016-01-28 at 13 51 21

miyagawa commented 8 years ago

It seems to me inside plenv init something is invoking bash which tries to initialize .bash_profile and that calls plenv init hence the infinite loop.

syohex commented 8 years ago

I cannot reproduce this issue with your vim configuration/setting and .bash_profile. I suppose this is your environment issue, not plenv.

miyagawa commented 8 years ago

@abra PLENV_DEBUG environment variable allows you to show the trace while executing plenv.

abra commented 8 years ago

I'm back. Link with result of PLENV_DEBUG.

abra commented 8 years ago

I've analysed my ~/.vimrc and found out that there are two lines which I forgot to remove earlier

let $BASH_ENV = ~/.bash_profile
set shell=/bin/bash

I've removed them and bash fork messages are gone.

syohex commented 8 years ago

:+1: