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

Segfaults in ZSH tab completion since installing RVM #4214

Open
mbellgb opened this issue Oct 27, 2017 · 23 comments

Comments

Projects
None yet
@mbellgb
Copy link

commented Oct 27, 2017

Description

I am using zsh as my login shell along with oh-my-zsh, but ever since installing RVM my terminal will sometimes segfault if I try to use tab to complete filenames (notably in conjunction with sudo).

This might be an upstream zsh issue, but seems unlikely since I haven't had this issue until installing zsh.

Steps to reproduce

  1. Use ZSH as login shell
  2. Install oh-my-zsh and rvm using instructions on their respective sites
  3. try to autocomplete file name with sudo, e.g. sudo cat .zshr<TAB>

Expected behavior

  1. Open terminal
  2. Type in sudo nvim /etc/hostn and pressing the <TAB> key to autocomplete to /etc/hostname

Actual behavior

  1. Open terminal
  2. Type in sudo nvim /etc/hostn
  3. Press <TAB>
  4. ZSH segfaults and terminal closes

Environment info + coredump

Gist containing coredump (coredumpctl dump zsh), backtrace printed from gdb, and output of omz_diagnostic_dump, which includes all of the ZSH environment variables, functions and aliases I am currently using in my terminal.

ruby-2.4.2:

  system:
    uname:        "Linux chancery-lane 4.13.8-1-ARCH #1 SMP PREEMPT Wed Oct 18 11:49:44 CEST 2017 x86_64 GNU/Linux"
    name:         "Arch"
    version:      "libc-2.26"
    architecture: "x86_64"
    bash:         "/usr/bin/bash => GNU bash, version 4.4.12(1)-release (x86_64-unknown-linux-gnu)"
    zsh:          "/usr/bin/zsh => zsh 5.4.2 (x86_64-unknown-linux-gnu)"
    remote_path:  "arch/libc-2.26/x86_64"

  rvm:
    version:      "1.29.3 (master)"
    updated:      "1 day 2 hours 31 minutes 53 seconds ago"
    path:         "/home/mbell/.rvm"
    autolibs:     "[4] Allow RVM to use package manager if found, install missing dependencies, install package manager (only OS X)."

  ruby:
    interpreter:  "ruby"
    version:      "2.4.2p198"
    date:         "2017-09-14"
    platform:     "x86_64-linux"
    patchlevel:   "2017-09-14 revision 59899"
    full_version: "ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]"

  homes:
    gem:          "/home/mbell/.rvm/gems/ruby-2.4.2"
    ruby:         "/home/mbell/.rvm/rubies/ruby-2.4.2"

  binaries:
    ruby:         "/home/mbell/.rvm/rubies/ruby-2.4.2/bin/ruby"
    irb:          "/home/mbell/.rvm/rubies/ruby-2.4.2/bin/irb"
    gem:          "/home/mbell/.rvm/rubies/ruby-2.4.2/bin/gem"
    rake:         "/home/mbell/.rvm/rubies/ruby-2.4.2/bin/rake"

  environment:
    PATH:         "/home/mbell/.rvm/gems/ruby-2.4.2/bin:/home/mbell/.rvm/gems/ruby-2.4.2@global/bin:/home/mbell/.rvm/rubies/ruby-2.4.2/bin:/home/mbell/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/opt/android-sdk/tools:/opt/android-sdk/tools/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/mbell/.rvm/bin:/home/mbell/scripts:/home/mbell/go/bin:/home/mbell/.yarn/bin:/home/mbell/node_modules/.bin:/home/mbell/.rvm/bin:/home/mbell/.rvm/bin"
    GEM_HOME:     "/home/mbell/.rvm/gems/ruby-2.4.2"
    GEM_PATH:     "/home/mbell/.rvm/gems/ruby-2.4.2:/home/mbell/.rvm/gems/ruby-2.4.2@global"
    MY_RUBY_HOME: "/home/mbell/.rvm/rubies/ruby-2.4.2"
    IRBRC:        "/home/mbell/.rvm/rubies/ruby-2.4.2/.irbrc"
    RUBYOPT:      ""
    gemset:       ""
@mbellgb

This comment has been minimized.

Copy link
Author

commented Oct 27, 2017

I've tested this with a fresh user account and the same error occurs. I didn't even have oh-my-zsh installed so that's definitely not the culprit here.

chancery-lane% sudo nvim /etc/mo*** Error in `-zsh': realloc(): invalid next size: 0x0000557a28089230 ***
[1]    29796 abort      sudo -u testusr -i

.zshrc:

# Lines configured by zsh-newuser-install
# End of lines configured by zsh-newuser-install
# The following lines were added by compinstall
zstyle :compinstall filename '/home/testusr/.zshrc'

autoload -Uz compinit
compinit
# End of lines added by compinstall

# Add RVM to PATH for scripting. Make sure this is the last PATH variable change.
export PATH="$PATH:$HOME/.rvm/bin"

gdb backtrace

(gdb) bt
#0  0x00007faa2c91e8a0 in raise () from /usr/lib/libc.so.6
#1  0x00007faa2c91ff09 in abort () from /usr/lib/libc.so.6
#2  0x00007faa2c961517 in __libc_message () from /usr/lib/libc.so.6
#3  0x00007faa2c967c84 in malloc_printerr () from /usr/lib/libc.so.6
#4  0x00007faa2c96c364 in _int_realloc () from /usr/lib/libc.so.6
#5  0x00007faa2c96d22e in realloc () from /usr/lib/libc.so.6
#6  0x0000557a27a2bb0e in zrealloc ()
#7  0x0000557a27a1e134 in expandjobtab ()
#8  0x0000557a27a1e1e2 in initjob ()
#9  0x0000557a279fe9e6 in ?? ()
#10 0x0000557a27a00318 in execlist ()
#11 0x0000557a27a26278 in execif ()
#12 0x0000557a279fd000 in ?? ()
#13 0x0000557a279fe6aa in ?? ()
#14 0x0000557a279fea92 in ?? ()
#15 0x0000557a27a00318 in execlist ()
#16 0x0000557a27a26278 in execif ()
#17 0x0000557a279fd000 in ?? ()
#18 0x0000557a279fe6aa in ?? ()
#19 0x0000557a279fea92 in ?? ()
#20 0x0000557a27a00318 in execlist ()
#21 0x0000557a27a26278 in execif ()
#22 0x0000557a279fd000 in ?? ()
#23 0x0000557a279fe6aa in ?? ()
#24 0x0000557a279fea92 in ?? ()
#25 0x0000557a27a00318 in execlist ()
#26 0x0000557a27a25e68 in execwhile ()
#27 0x0000557a279fd000 in ?? ()
#28 0x0000557a279fe6aa in ?? ()
#29 0x0000557a279fea92 in ?? ()
#30 0x0000557a27a00318 in execlist ()
#31 0x0000557a27a25210 in execfor ()
#32 0x0000557a279fd000 in ?? ()
#33 0x0000557a279fe6aa in ?? ()
#34 0x0000557a279fea92 in ?? ()
#35 0x0000557a27a00318 in execlist ()
#36 0x0000557a27a008cb in execode ()
#37 0x0000557a27a00a61 in ?? ()
#38 0x0000557a279fda93 in ?? ()
#39 0x0000557a279fe6aa in ?? ()
#40 0x0000557a279fea92 in ?? ()
#41 0x0000557a27a00318 in execlist ()
#42 0x0000557a27a008cb in execode ()
#43 0x0000557a27a017d8 in runshfunc ()
#44 0x00007faa2b82b8c9 in ?? () from /usr/lib/zsh/5.4.2/zsh/complete.so
#45 0x0000557a27a0147d in runshfunc ()
#46 0x0000557a27a0211e in doshfunc ()
#47 0x0000557a27a02500 in ?? ()
#48 0x0000557a279fdcdf in ?? ()
#49 0x0000557a279fe6aa in ?? ()
#50 0x0000557a279fea92 in ?? ()
#51 0x0000557a27a00318 in execlist ()
#52 0x0000557a27a2623e in execif ()
#53 0x0000557a279fd000 in ?? ()
#54 0x0000557a279fe6aa in ?? ()
#55 0x0000557a279fea92 in ?? ()

@pkuczynski

This comment has been minimized.

Copy link
Member

commented Oct 28, 2017

Does the same thing happen when you remove RVM? Hard to imagine how we could cause this issue...

@mbellgb

This comment has been minimized.

Copy link
Author

commented Oct 28, 2017

@pkuczynski Nope, problem does not occur when I remove RVM from my .profile and .zshrc files. However, using a minimal zshrc, I notice that the error only occurs when I have the following lines in my zshrc:

autoload -Uz compinit
compinit

These are lines added to zshrc by the zsh new user wizard, so I'm not entirely sure why they would cause segfaults?

@RGBD

This comment has been minimized.

Copy link

commented Nov 2, 2017

I have the same problem with prezto. Same zsh and rvm version. In my case "sudo nvim ..." works, but when i type git checkout <TAB> i get the segfault. However, when I type git checkout<TAB> (no space) the command doesn't segfault, and any later completions for git command won't cause segfaults.
@mbellgb, would any logs be of help?

@mbellgb

This comment has been minimized.

Copy link
Author

commented Nov 3, 2017

@RGBD Interesting, do you happen to have the stack trace of the segfault?

@ziyan-junaideen

This comment has been minimized.

Copy link

commented Nov 5, 2017

I am having a similar issue. Here is an interesting observation. I am not sure how to use a gbd to make a stack trace for a tab completion.

I am not having

autoload -Uz compinit
compinit

This is how it behaves

Error

  • New terminal
  • sudo vim /et<tab>
  • Bang!

Fine

  • New terminal
  • sudo v<tab> => sudo vim
  • sudo vim /et<tab> => sudo vim /etc/
  • Then clear thing sup and sudo vim /et<tab> no more issues
@ziyan-junaideen

This comment has been minimized.

Copy link

commented Nov 5, 2017

I think it is a bug in ZSH that is elevated by some thing with RVM. If you down grade to 5.3.1 it would be fine.

I installed Arch y'day and finished setting up ZSH and went to bed at 4am. Few hours later I am like 'Debian wouldn't do this'.

@ar1a

This comment has been minimized.

Copy link

commented Nov 14, 2017

still getting this, will try a downgrade

EDIT: downgrading to 5.3.1 fixed this.

@mbellgb

This comment has been minimized.

Copy link
Author

commented Nov 14, 2017

@ziyan-junaideen you're experiencing exactly what I've seen, so good to know I'm not alone!

(Btw, you can examine coredumps using coredumpctl: https://wiki.archlinux.org/index.php/Core_dump#Examining_a_core_dump)

@jackrandom

This comment has been minimized.

Copy link

commented Jan 2, 2018

same behaviour with zsh 5.4.2-1 from arch repos.
had to record the screen to read the error from zsh. Will try to downgrade and update post.

UPDATE: can confirm this doesn't happen at all with zsh 5.3.1-2 (from arch)

now I'm not sure whether to file a bugreport at zsh and/or arch bugtracker, as it seems all people affected are arch users.

Can someone confirm the bug with an up-to-date Fedora/Ubuntu/any distro not arch but having zsh 5.4.x ?

@maximbaz seems like a nice workaround, but not satisfying in long term. I use rvm on a daily basis.

@maximbaz

This comment has been minimized.

Copy link

commented Jan 3, 2018

If you don't use rvm daily, but still need to keep it around for occasional needs, I have a tip to share. You can postpone sourcing rvm until the first time you execute rvm command. I do this and this way I'm less affected by this bug, as zsh crashes on tab completion only if I used rvm command in that terminal at least once. Still annoying, but less annoying 🙂 As a bonus, you will notice that your terminal starts faster, because sourcing rvm is a quite slow operation.

How to do this: click and click.

Note that there might be a script /etc/profile.d/rvm.sh that sources rvm automatically (at least AUR package creates it on Arch Linux), you need to make sure that file is not sourced by your terminal.

@erikw

This comment has been minimized.

Copy link

commented Jan 10, 2018

@maximbaz Thanks for the tip!

This makes the segfault less likely to happen as I don't use rvm(1) on a daily basis. As a bonus my shell starts faster now with this lazy loading :D

@jackrandom

This comment has been minimized.

Copy link

commented Feb 5, 2018

will this get a proper solution?

@mpapis

This comment has been minimized.

Copy link
Member

commented Feb 6, 2018

I have been fixing multiple issues in ZSH integration that were caused by freaky behaviors of ZSH, this is probably fixable but would require lot's of time from my side, please try with different versions of ZSH, we could add bootup checks to exclude the failing versions loading RVM.

@pdf

This comment has been minimized.

Copy link

commented Mar 16, 2018

I don't think failing to load on ZSH >= 5.4.0 will turn out to be a viable long-term strategy. Though clearly this is a ZSH bug (although I've certainly only ever seen it happen if RVM is loaded) and they're corrupting the stack somewhere, so I guess fingers crossed it gets fixed upstream if there's not likely to be a fix here.

Does anyone know if there's an upstream bug for this (or for that matter, where/how ZSH does bug tracking)?

@cbcoutinho

This comment has been minimized.

Copy link

commented Mar 17, 2018

I'm having the same issue on OpenSUSE Tumbleweed where tab completion fails using sudo on some file in /etc/..., so at least I can report this is not an Arch-only issue

chris@tumbleweed:~> zsh --version
zsh 5.4.2 (x86_64-suse-linux-gnu)

On my OpenSUSE Leap 15 Beta test machine, I don't experience these zsh tab errors.

chris@leap15-vm:~> zsh --version
zsh 5.3.1 (x86_64-suse-linux-gnu)
@pdf

This comment has been minimized.

Copy link

commented Mar 20, 2018

I just tested against zsh v5.4.1 and that appears to behave as expected, so looks like this was something introduced in the last point release in zsh, should help narrow things down a bit.

@jackrandom

This comment has been minimized.

Copy link

commented Mar 23, 2018

Well, I'm using rbenv now, as this probably won't get fixed anytime soon. It doesn't hack into your shell that much and is way less buggy IMHO. Also, shell starts faster in contrast to loading RVM.

@winny-

This comment has been minimized.

Copy link

commented Apr 7, 2018

I reported this issue upstream to zsh. https://www.zsh.org/mla/users/2018/msg00273.html

@okapia

This comment has been minimized.

Copy link

commented Apr 7, 2018

If anyone is able to reproduce this consistently, can you try using a debug build of zsh. Ideally enable gcc's address sanitizer. Or perhaps run zsh with valgrind. Given a proper core dump with debug symbols or even just a stack trace, it might be a lot easier to find the cause. From the backtrace above I'd suspect memory corruption is preceding the actual crash. I've tried installing rvm and trying to reproduce this without success.

@matthias-g

This comment has been minimized.

Copy link

commented Jun 20, 2018

It seems to me that this commit fixes the bug. It is included in releases from zsh 5.5 on.

@hickscorp

This comment has been minimized.

Copy link

commented Aug 9, 2018

I'm on Xubuntu 18.04. Using zsh 5.5.1 from the 18.10 repo fixed this issue for me. It'd be great to see this merged for 18.04 LTS too!

For those who need help, just download these 3 packages:

Then install them all using sudo dpkg -i *.deb.
You might then need to fix dependencies by running sudo apt-get install -f.

@jackrandom

This comment has been minimized.

Copy link

commented Feb 13, 2019

this can be closed. as multiple users report (can confirm myself), this doesn't happen anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.