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-Init Broken for SSH w/ Bash #2367
Comments
|
I cannot reproduce this in a fresh Ubuntu Server 20.04 or 22.04 VM. Do you have |
|
My prod servers do not have Thanks! |
|
From what you and @stevemuskiewicz reported, it looks like something is causing one of the Bash startup files to be sourced in the Prepend all the Bash startup files with the following code to see which of them is being sourced then search for any references to that file across the server to find out what can be causing that. export PS4='+(${BASH_SOURCE:-}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -x |
That said, if your SSH server is set up to allow injecting environment from the client (the default is not IIRC), your SSH client configuration may be causing that, too. |
@kopfjager007 , if you upload the image of that test VM to some cloud storage, I may be able to reproduce the issue with it. Make sure to include reproduction steps, too. |
That is the output of the For the VM, it's literally just a vanilla Ubuntu 20.04 server; no special setup or files outside of creating a export PS4='+(${BASH_SOURCE:-}:${LINENO}): ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -xv
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# Load the default .profile
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile"I built the VM from the latest Ubuntu 20.04LTS server ISO image, installed ssh and pyenv, and that's literally all I did. I don't have anything special on my end with SSH; all I'm doing is Setup: I installed SSH with: apt install sshThen i installed Pyenv: curl --silent --location https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer --output pyenv-installer
export PATH=$PATH:/root/.pyenv/bin
/bin/bash pyenv-installerConfirmed Pyenv is working: pyenv --versionI initially added this to export PYENV_ROOT="/root/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"Now I leave VMware and access the VM via SSH and notice the issue. I added those lines to |
|
I have reproduced this issue on a freshly installed Fedora 36 installation. |
|
As an additional - commenting out line 151 in pyenv-init also fixed the problem for me. That line clearly doesn't work over ssh - thank you @kopfjager007! I guess I will wait to see what the actual fix is as my Shell-fu isn't good enough to understand the line. |
|
I have the same problem on a fresh installation of Debian 11. Thank you |
|
I also have this issue on Ubuntu. I reproduced on Ubuntu 20.04. Is the problem line 151 even necessary if it's causing an infinite loop of bash processes? A lot of people access servers over SSH and use bash. If i comment it out like @leepa mentioned everything seems fine. |
|
Came here in search of a solution to this as well. I am experiencing this across my systems, all which are Ubuntu 20.04 that I ssh into. I see some workarounds, but I can confirm seeing line 151 in pyenv-init causing the issue. I can provide details if necessary, but @kopfjager007 fully detailed exactly what I am seeing. |
|
Okay, thanks to @martindorey's #264 (comment), I found out why this happens -- and why I couldn't reproduce it. Some distros, notably Debian (and hence its derivatives), uncomment a non-default option in Bash's source to source However, Debian's stock case $- in
*i*) ;;
*) return;;
esacWhich negates that behavior when Bash is run noninteractively. Looks like some people are fond of removing that guard or running stuff before it... |
|
Though there are valid cases to want to source some standard shell startup file when running noninteractive commands via SSH. So I'm fine with adding |
|
Thanks @native-api and @kopfjager007 for chasing this one down. Looks like Fedora/RH doesn't have the bash "guard" in their default |
|
@native-api You are correct, part of my automated installation script up until Pyenv version 2.2.5 I could do this: The second part inserts those two lines above the guard: I'm not quite following why this was working fine up until Pyenv 2.2.5 , and now it suddenly doesn't anymore. But the solution is that I need to find a way to insert those two lines after the guard. Is this correct? Because looking at your commit that you merged against this issue, it seems you only added documentation and there is no change to the actual code. Thanks for clarifying |
It's a big comment, because this was really quite non-obvious, but I see |
System
Pyenv was Installed via Pyenv Installer. Per the Pyenv Readme, I added the following lines to my
~/.bashrc,~/.bash_profile, and~/.profilefiles:Running
pyenv doctorshows no errors and states pyenv was installed successfully. I have no issue running any pyenv commands at this stage and can install and use python versions through pyenv without issue.Issue
The issue I'm experiencing is when accessing my server via SSH with the default login shell set to
/bin/bash, the login prompt seems to hang indefinitely. This does not happen when the default shell is set to/bin/zsh, nor does it happen when I login at the server using a keyboard/monitor. This seems to be unique to SSH w/ Bash.While troubleshooting the issue I noticed several hundred, and eventually thousands, of new Bash processes (ran

ps aux):While the terminal appears to be hung, new bash processes spawn at a rate of about 1000 every ~30 seconds.


While at the apparently hung shell, I

^Cand am dropped in at the bash prompt, but there are obvious other issues since it seems wheneval "$(pyenv init -)"runs in~/.bash_profile, bash never sources.bashrcor.profile. Wherever that eval is is where this issue begins.Given the process listing and some debugging, I believe this is related to Line 151 in pyenv/libexec/pyenv-init in the latest 2.3.0 release; commit 8439f8e18714c2aec0399e9cea022467dc4511ff. If i comment this line out and initiate a new SSH connection, I don't have any issue and don't get thousands of bash processes (which I assume will eventually exhaust resources).
Dropping into

/bin/zshit's clear that the install was successful and Pyenv works.I did add the recommended debug envvar for pyenv (
trace.log) and I also did some shell debugging (debug.log.1) that I will drop here if that will help.Logs
trace.log
debug.log
Note: debug.log line 338 is where the hang was observed. I then
^C'd .The text was updated successfully, but these errors were encountered: