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

pyenv shims fail with concurrent processes in a build system #174

Closed
rocktavious opened this issue May 21, 2014 · 6 comments
Closed

pyenv shims fail with concurrent processes in a build system #174

rocktavious opened this issue May 21, 2014 · 6 comments

Comments

@rocktavious
Copy link

There appears to be a race condition if there is a pyenv installation on a build machine that runs multiple processes which create virtualenv's via the command :
pyenv virtualenv name of env

When there are two concurrently running processes that try to create a virtualenv for each process there is a race condition when the second process runs the command to create a new virtualenv it eventually makes a call to rehash and errors because of:
pyenv: cannot rehash: /var/lib/jenkins/.pyenv/shims/.pyenv-shim exists

I fully understand if this is a limitation of the way pyenv shims work, but i'm wondering if there is a workaround for this. Since shim's are path based and each process can have its own environment variables, it would be nice if each process could specify a location for its set of shims so multiple processes on the same machine using pyenv won't collide when the shims are rehashed.

I would think something much like the PYENV_ROOT env var. It could be PYENV_SHIM_ROOT env var that tells pyenv where to place the shims and if not specified it could default to the standard location.

Let me know if there is anyway i can help make this a reality.

@yyuu yyuu added the question label May 21, 2014
@yyuu
Copy link
Contributor

yyuu commented May 21, 2014

Yep, there is race condition in pyenv-rehash what it is hard to deal with.

I'm not sure if this is worth for your situation, the Jenkins' plugin of pyenv is providing lock mechanism based on mkdir to avoid concurrent invocations of pyenv-rehash from pyenv-install. Please look at how it is deal with the problem.

https://github.com/jenkinsci/pyenv-plugin/blob/master/lib/pyenv/semaphore.rb

@rocktavious
Copy link
Author

So i have successfully worked around the problem by using the jenkins pyenv plugin to but it seems this plugin doesn't install all of the extra helpers that pyenv-installer does, as it fails in a later build step when i'm calling:
pyenv activate env name

it says that i need to restart my shell as the virtualenv plugin is not installed properly. Its confusing because the preceding step worked:
pyenv virtualenv env name

Is there a way to get the jenkins pyenv plugin to install all of the extra helpers that pyenv-installer does?

@yyuu
Copy link
Contributor

yyuu commented May 21, 2014

Unfortunately, there is no way to install extra pyenv plugins via Jenkins pyenv plugin for now. Please write job script to do special tasks.

@rocktavious
Copy link
Author

So it seems with the jenkins pyenv plugin i still get the concurrency issues but less often? I can move the discussion over to that repo if you'd like but here is the console output from jenkins when the failure happens

Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
Commencing build of Revision 473910699523ae04d814b2c814ef2c4f8e3b8e68 (origin/master)
Checking out Revision 473910699523ae04d814b2c814ef2c4f8e3b8e68 (origin/master)
$ bash -c "[ -d $HOME/.pyenv ]"
$ bash -c "cd /var/lib/jenkins/slave-builds/workspace/Diagnose_Merge_Conflicts@2 && env PYENV_ROOT=$HOME/.pyenv PYENV_VERSION=2.6.6 $HOME/.pyenv/bin/pyenv local 2>/dev/null || true"
$ bash -c "mkdir $HOME/.pyenv.lock"
$ bash -c "env PYENV_ROOT=$HOME/.pyenv PYENV_VERSION=2.6.6 $HOME/.pyenv/bin/pyenv versions --bare"
$ bash -c "env PYENV_ROOT=$HOME/.pyenv PYENV_VERSION=2.6.6 $HOME/.pyenv/bin/pyenv rehash"
pyenv: cannot rehash: /var/lib/jenkins/.pyenv/shims/.pyenv-shim exists
$ bash -c "rmdir $HOME/.pyenv.lock"
FATAL: (CommandError) failed: "env PYENV_ROOT=$HOME/.pyenv PYENV_VERSION=2.6.6 $HOME/.pyenv/bin/pyenv rehash"
org.jruby.exceptions.RaiseException: (CommandError) failed: "env PYENV_ROOT=$HOME/.pyenv PYENV_VERSION=2.6.6 $HOME/.pyenv/bin/pyenv rehash"
at Pyenv::InvokeCommand.run(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/lib/pyenv/invoke.rb:18)
at Pyenv::Environment.pip_install!(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/lib/pyenv.rb:80)
at Pyenv::Environment.setup!(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/lib/pyenv.rb:32)
at Pyenv::Semaphore.synchronize(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/lib/pyenv/semaphore.rb:15)
at Pyenv::Semaphore.synchronize(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/lib/pyenv/semaphore.rb:13)
at Pyenv::Environment.setup!(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/lib/pyenv.rb:24)
at PyenvWrapper.setup(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/models/pyenv_wrapper.rb:57)
at Jenkins::Model::EnvironmentProxy::InstanceMethods.setUp(/var/lib/jenkins/plugins/pyenv/WEB-INF/classes/vendor/gems/gems/jenkins-plugin-runtime-0.2.3/lib/jenkins/model/environment_proxy.rb:8)

@yyuu yyuu added the wontfix label Oct 9, 2014
@yyuu
Copy link
Contributor

yyuu commented Oct 9, 2014

pyenv is not process safe for now. Please use external lock mechanism (e.g. like jenkins-pyenv-plugin is doing) to avoid race conditions.

@yyuu yyuu closed this as completed Oct 9, 2014
@columbusmonkey
Copy link

Where is the issue tracker for the jenkins-pyenv-plugin? (As it looks like it may remove the lock directory, even if it did not manage to create it.)

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

No branches or pull requests

3 participants