Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fork failed: resource temporarily unavailable #1509

Closed
acarpe opened this issue Dec 20, 2012 · 37 comments · Fixed by #2827
Closed

fork failed: resource temporarily unavailable #1509

acarpe opened this issue Dec 20, 2012 · 37 comments · Fixed by #2827

Comments

@acarpe
Copy link

acarpe commented Dec 20, 2012

I'm on OS X 10.8.2
after upgrading to latest oh-my-zsh I started to have these errors:

Last login: Thu Dec 20 23:36:28 on ttys002
/Users/myuser/.oh-my-zsh/oh-my-zsh.sh:4: fork failed: resource temporarily unavailable
git_compare_version:4: fork failed: resource temporarily unavailable
/Users/myuser/.oh-my-zsh/oh-my-zsh.sh:4: fork failed: resource temporarily unavailable
git_compare_version:4: fork failed: resource temporarily unavailable
/Users/myuser/.zshrc.local:53: fork failed: resource temporarily unavailable
_current_epoch:1: fork failed: resource temporarily unavailable

it turns out the problem is in on-my.zsh.sh

  # Check for updates on initial load...
  if [ "$DISABLE_AUTO_UPDATE" != "true" ]
  then
    /usr/bin/env ZSH=$ZSH zsh $ZSH/tools/check_for_upgrade.sh
  fi

I have changed to use sh instead of zsh and everything started to work again:

  # Check for updates on initial load...
  if [ "$DISABLE_AUTO_UPDATE" != "true" ]
  then
    /usr/bin/env ZSH=$ZSH sh $ZSH/tools/check_for_upgrade.sh
  fi
@wangxiaomo
Copy link

+1 . i got this problem too.

@nocksock
Copy link

+1 I get this problem occasionally as well.

@akrueger
Copy link

akrueger commented Mar 2, 2014

I tried that fix but received a bunch of nasty zsh errors.

I don't know what is doing it, but that if statement is running a bajillion times and creating a bajillion processess.

@mcornella
Copy link
Member

Hi @akrueger, paste you zshrc file and double check you have ohmyzsh updated.

@akrueger
Copy link

akrueger commented Mar 2, 2014

oh-my-zsh is updated. I have included one extra theme in the themes folder.

.zshrc

# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh

ZSH_THEME="prose"

plugins=(git)

source $ZSH/oh-my-zsh.sh

# User configuration

export PATH="/Library/Frameworks/Python.framework/Versions/3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin"

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

PATH="/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"

@akrueger
Copy link

akrueger commented Mar 2, 2014

As a temporary solution, I've just commented out:

Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
  /usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh
fi

About 500 processes get launched on login (terminal tab opening) if those lines are active.

@mcornella
Copy link
Member

Oh right, I thought that line was already fixed. Change zsh -f for sh on that line, as the OP suggests. See if it helps

@akrueger
Copy link

akrueger commented Mar 2, 2014

When I do that, I get errors.

A ton of this:

/Users/akrueger/.oh-my-zsh/oh-my-zsh.sh: line 13: `for config_file ($ZSH/lib/*.zsh); do'

and this:

/Users/akrueger/.oh-my-zsh/oh-my-zsh.sh: line 1: Check: command not found

@mcornella
Copy link
Member

The first line is actually a comment so leave it commented. That's for the second error.
As for the first error, are you using zsh to open the terminal? Run echo $SHELL to check that

@akrueger
Copy link

akrueger commented Mar 2, 2014

Yea, first line wasn't active. Error still persists when it looks like this:

# Check for updates on initial load...
if [ "$DISABLE_AUTO_UPDATE" != "true" ]; then
  /usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT sh $ZSH/tools/check_for_upgrade.sh
fi

zsh is indeed the default shell.

@mcornella
Copy link
Member

Ok I think I'm onto something. Write echo $SHELL just below the fi line.

@akrueger
Copy link

akrueger commented Mar 2, 2014

Runs twice with the opening if statement commented out:

/bin/zsh
/bin/zsh

With the if statement active, produces many of these:

/Users/akrueger/.oh-my-zsh/oh-my-zsh.sh: line 15: syntax error near unexpected token `('
/Users/akrueger/.oh-my-zsh/oh-my-zsh.sh: line 15: `for config_file ($ZSH/lib/*.zsh); do'
/bin/zsh

@mcornella
Copy link
Member

I'm sorry, I have no idea what is happening. We need to take a step back and start ruling out hypotheses. Start with a clean zshrc; you can copy the one inside the template folder. If that doesn't help, use a fresh copy of oh-my-zsh, and so on.

@akrueger
Copy link

akrueger commented Mar 5, 2014

I can't say definitively, but I think this may be a problem with oh-my-zsh.

I have uninstalled it and zsh, added back zsh through homebrew (and
switched control to it), then readded oh-my-zsh. Immediate on installation
it gave me this:

SnowCrash% which zsh
/usr/local/bin/zsh
SnowCrash% curl -L
https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time
 Current
                                 Dload  Upload   Total   Spent    Left
 Speed
100  1859  100  1859    0     0   2308      0 --:--:-- --:--:-- --:--:--
 2306
Cloning Oh My Zsh...
Cloning into '/Users/akrueger/.oh-my-zsh'...
remote: Reusing existing pack: 8716, done.
remote: Total 8716 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (8716/8716), 1.83 MiB | 1.46 MiB/s, done.
Resolving deltas: 100% (4307/4307), done.
Checking connectivity... done
Looking for an existing zsh config...
Found ~/.zshrc. Backing up to ~/.zshrc.pre-oh-my-zsh
Using the Oh My Zsh template file and adding it to ~/.zshrc
Copying your current PATH and adding it to the end of ~/.zshrc for you.
Time to change your default shell to zsh!
Changing shell for akrueger.
Password for akrueger:
chsh: no changes made
         __                                     __
  ____  / /_     ____ ___  __  __   ____  _____/ /_
 / __ \/ __ \   / __ `__ \/ / / /  /_  / / ___/ __ \
/ /_/ / / / /  / / / / / / /_/ /    / /_(__  ) / / /
\____/_/ /_/  /_/ /_/ /_/\__, /    /___/____/_/ /_/
                        /____/


 ....is now installed.


 Please look over the ~/.zshrc file to select plugins, themes, and options.
/etc/zshenv:3: fork failed: resource temporarily unavailable
/Users/akrueger/.oh-my-zsh/oh-my-zsh.sh:3: fork failed: resource
temporarily unavailable
git_compare_version:4: fork failed: resource temporarily unavailable
_current_epoch:1: fork failed: resource temporarily unavailable
SnowCrash%

On Wed, Mar 5, 2014 at 12:34 PM, Marc Cornellà notifications@github.comwrote:

I'm sorry, I have no idea what is happening. We need to take a step back
and start ruling out hypotheses. Start with a clean zshrc; you can copy the
one inside the template folder. If that doesn't help, use a fresh copy of
oh-my-zsh, and so on.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1509#issuecomment-36776446
.

@mcornella
Copy link
Member

I agree, the issue must be with oh-my-zsh. If executing the line

/usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -f $ZSH/tools/check_for_upgrade.sh

spits these errors then that's the problem.

So let's split that statement in parts, see what we're working with:

  • /usr/bin/env: is there an issue with env? What version is it? Run /usr/bin/env --version.
  • zsh -f: is that working as expected? Running zsh -f should give you a plain boring prompt like the one you had before installing oh-my-zsh (SnowCrash%). Also, what version is it? Run zsh --version.
  • $ZSH/tools/check_for_upgrade.sh: is the issue in that script? Writing a return statement in the beginning of the file (below the first line), does the problem persists?

That's pretty much what I'd do if I encountered this issue. I suspect the problem will be in the script, or in a combination of the installed zsh and the script.

@akrueger
Copy link

akrueger commented Mar 6, 2014

With the if statement commented out:

/usr/bin/env --version is not a known command. This is the info I get:

/usr/bin/env
PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
TMPDIR=/var/folders/_1/4dk01vtn6756lbg0r2kfffwr0000gn/T/
SHELL=/bin/zsh
HOME=/Users/akrueger
USER=akrueger
LOGNAME=akrueger
TERM_PROGRAM=iTerm.app
LANG=en_US.UTF-8
PWD=/Users/akrueger
ITERM_PROFILE=Hotkey Window
TERM=xterm-256color
ITERM_SESSION_ID=w0t0p0
SHLVL=1
OLDPWD=/Users
_=/usr/bin/env

I am unsure why my SHELL is listed as /bin/zsh I have altered the etc/shells file and entered

chsh -s /usr/local/bin/zsh

zsh -f does indeed change the prompt

zsh--both for /bin/zsh and /usr/local/bin/zsh --is zsh 5.0.5 (x86_64-apple-darwin13.0.0)

I am not able to execute $ZSH/tools/check_for_upgrade.sh Is this necessary considering my version?

@mcornella
Copy link
Member

Both env and zsh seem to be fine. The fact that your shell is /bin/zsh shouldn't be an issue since both are the same version.
Let's debug the script then. There are a couple of arguments that make zsh run in verbose mode; add -xv to zsh, like this.

/usr/bin/env ZSH=$ZSH DISABLE_UPDATE_PROMPT=$DISABLE_UPDATE_PROMPT zsh -xv -f $ZSH/tools/check_for_upgrade.sh

Then open a terminal and copy the output.

@akrueger
Copy link

akrueger commented Mar 6, 2014

Terminal output too long. What's the best way for me to to get it to you?

@ncanceill
Copy link
Contributor

gist.github.com

You can access it by clicking the "Gist" button at the top of this very page.

Otherwise, use pastebin or some other similar tool.

Or just drop him an email at marc(dot)cornella(at)live(dot)com

@akrueger
Copy link

akrueger commented Mar 6, 2014

@mcornella
Copy link
Member

There it is:

[ -f ~/.profile ] && source ~/.profile
+/Users/akrueger/.oh-my-zsh/tools/check_for_upgrade.sh:23> [ -f /Users/akrueger/.profile ']'
+/Users/akrueger/.oh-my-zsh/tools/check_for_upgrade.sh:23> source /Users/akrueger/.profile
source $ZSH/oh-my-zsh.sh+/Users/akrueger/.profile:1> source /Users/akrueger/.oh-my-zsh/oh-my-zsh.sh

The script sources the file .profile. In that file there is the line source $ZSH/oh-my-zsh.sh, so you have a circular reference which triggers the massive opening of processes.
Try removing that line from .profile file.

Haven't looked at the rest though, may be something else there.

@akrueger
Copy link

akrueger commented Mar 6, 2014

Oh geez. facepalm

I never look in the .profile

Thanks for the help! Looks like oh-my-zsh wasn't the culprit--which is good.

@mcornella
Copy link
Member

I wonder if the other people had that line in their .profile file too, maybe from a prior installation of oh-my-zsh. I'm cc-ing @acarpe to see if this can be closed.
Cheers!

@chrillewoodz
Copy link

This happens constantly when running an ios simulator..

@donnfelker
Copy link

Just ran into this problem when the Android emulator System UI crashed. Saw @chrillewoodz comment above about the iOS simulator and decided to kill the Android emulator. Sure enough, as soon as I killed the emulator, restarted the terminal all was fine. Very odd. Leaving a comment here for future folks who run across this issue.

@jomla97
Copy link

jomla97 commented Feb 15, 2018

Closing both my iOS simulator and Android emulator solved this for me too. +1!

@elahmo
Copy link

elahmo commented Dec 13, 2018

Anyone figured out why is this happening?

I get this with VSCode, doing python development (regular project), with flake linting. And it always happens that python creates more than 500 threads (parent is VSCode), and I get this message across my terminals.

@LarryWachira
Copy link

LarryWachira commented Dec 14, 2018

Got this today too for the first time ever @elahmo, shortly after updating VSCode. Did you update as well?

@elahmo
Copy link

elahmo commented Dec 14, 2018

@LarryWachira I got updated few days ago I think, I remember seeing that changelog but dont know which day was it.

I am on 1.30.0 (1.30.0).

@LarryWachira
Copy link

Same here @elahmo, I am on 1.30.0 and the error started showing up after I updated. Should probably look at all of the stuff that was changed, might be something in the settings we could turn off.

@mcornella
Copy link
Member

A fork failed: resource temporarily unavailable message can be due to many things, it's not necessarily due to OMZ. If all of you are having this problem with VSCode I suggest asking on the project's repository.

@xbtlin
Copy link

xbtlin commented Dec 18, 2019

The same problem, reboot will solve.

@AdamKyle
Copy link

The same problem, reboot will solve.

Ya try having to do that at least once a day with a hard reboot because of this issue.

@mcornella
Copy link
Member

Try looking for long chained processes in ps command with a tree output (in my system, ps axf prints process trees; pstree also works if you can get it). Of course you won't be able to do that once you get the fork failed error, so you need to do that frequently enough that you catch the culprit. You can run watch in a separate terminal and take a snapshot of running processes every 5 seconds or something like that.

@chucklessmith
Copy link

I just found ~1000 instances of cron running on my machine, after having to restart it this morning due to this error. Reasonably sure that's related to the ongoing instability.

@yogithesymbian
Copy link

yogithesymbian commented May 8, 2023

any other alternative ? instead of reboot machine / server ?
parse_git_dirty:18: fork failed: resource temporarily unavailable

@eduardo-lisboa-picpay
Copy link

Thank you very much. Just made this change here and it seems to have solved my problem as well. Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet