iTerm2 crashes #107

Closed
thenitai opened this Issue Feb 7, 2016 · 15 comments

6 participants

@thenitai

(As requested in #103 I created this as a separate topic)

While the initial error is now resolved the plugin now crashes my terminal window as soon as I enter a "space" after any command, i.e. "ping(space)".

I'm using iTerm2 and load all plugins with the zgen framework. Here is my setup:

In a .zgen file

source ~/.zsh/zsh-autosuggestions/dist/autosuggestions.zsh
zgen load zsh-users/zsh-syntax-highlighting

In .zshrc

ZSH_AUTOSUGGEST_CLEAR_WIDGETS=("${(@)ZSH_AUTOSUGGEST_CLEAR_WIDGETS:#(up|down)-line-or-history}")

ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(history-substring-search-up history-substring-search-down)

autosuggest_start

Your plugin is loaded from the repro and is on the v0.1.0 branch.

@kergoth

I'm seeing a similar behavior, except that it's not a crash, and it's when I hit tab, not space. In my case, the iterm2 window closes because the process exited, because zsh segfaulted. Haven't had time to investigate further, my gdb-fu is weak.

@andrewsuzuki

@kergoth Same problem here, I'm using the latest iTerm2 nightly and pressing tab immediately closes the window.

@ericfreese
zsh-users member

Can you confirm you still have this problem with a minimal configuration?

Try installing with:

$ git clone git://github.com/tarruda/zsh-autosuggestions ~/.zsh/zsh-autosuggestions

and confirming you have the latest version:

$ git -C ~/.zsh/zsh-autosuggestions rev-parse --short HEAD
011f542

and using the following .zshrc:

source ~/.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh

Then start a new terminal session and confirm the problem persists.

@kergoth

zsh does not crash in that case, here. I'll try to isolate the configuration which crashes.

@ericfreese
zsh-users member

I'll try to isolate the configuration which crashes.

Thanks! In my experience this is usually caused by something invoking a zle widget that is in one of these lists. This causes an infinite recursion and segfault. So, when isolating, it might help to look for lines that call zle. Let me know what you find!

@lexinator

I've been trying to narrow it down to specific line and so far zsh-syntax-highlighting and zsh-history-substring-search cause the similar coredump. This happens on both zsh v5.0.8 and v5.2. The sourcing order does matter. If I do zsh-syntax-highlighting first and then zsh-autosuggestions.zsh it does not coredump as noted below. set -x has not revealed anything obvious either.

% /bin/zsh --version
zsh 5.0.8 (x86_64-apple-darwin15.0)
% /bin/zsh -f
% cd ~/src/zsh-autosuggestions
% % git rev-parse --short HEAD
011f542
% . ./zsh-autosuggestions.zsh
% cd ~/src/zsh-syntax-highlighting
% git remote -v | tail -1
origin  git://github.com/zsh-users/zsh-syntax-highlighting.git (push)
% git rev-parse --short HEAD
683f483
% . ./zsh-syntax-highlighting.zsh
% <any character>
% zsh: segmentation fault  /bin/zsh -f
@ericfreese
zsh-users member

and it's when I hit tab

@kergoth This is another clue. What is tab bound to? Run bindkey '^I' to find out

@ericfreese
zsh-users member

Thanks @lexinator I'll look into this.

@lexinator

both zsh-syntax-highlighting and zsh-history-substring-search define zle, and the coredump is 500ish level stacktrace, so I suspect your theory on recursive zle is correct. thanks.

@kergoth

Indeed, thanks for the guidance, you're absolutely correct. Is the correct fix to add the zle widgets in question that call the originals to ZSH_AUTOSUGGEST_MODIFY_WIDGETS?

@ericfreese
zsh-users member

@lexinator I believe the segfault you produced above is created by loading zsh-syntax-highlighting after _zsh_autosuggest_start has been called and the widgets have been bound. Widget binding is delayed by the plugin by using add-zsh-hook to run a function before each new prompt. Because you're sourcing syntax-highlighting at a different prompt, that hook has already run and the widgets have already been bound.

Sourcing both plugins at the same prompt (simulating the behavior of loading .zshrc) avoids the problem:

% /bin/zsh -f
% . ~/src/zsh-autosuggestions/zsh-autosuggestions.zsh; . ~/src/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
@ericfreese
zsh-users member

@kergoth

Is the correct fix to add the zle widgets in question that call the originals to ZSH_AUTOSUGGEST_MODIFY_WIDGETS?

My personal belief (though I have yet to confirm it) is that the correct fix is for any plugin invoking a widget that it does not have control over to do one of two things:

  1. Use the builtin dot-prefixed version of the widget instead if the plugin only wants the default behavior to occur (i.e. use zle .self-insert instead of zle self-insert in case the self-insert widget has been overridden by someone).
  2. Call zle with the -w flag to set $WIDGET and other associated variables correctly when the widget is invoked if the plugin doesn't particularly care what happens when the widget is invoked.

Though it seems there's a lot of code out there that does neither of these things and just calls possibly user-defined widgets without the -w flag set. zsh-history-substring-search does it here, bracketed-paste-magic does it here and here, and I'm sure that's just the beginning. So this makes me wonder if I'm wrong in my assumption and that I should be handling things differently in this plugin. Especially since I'm relatively new to all of this.

So for now, yeah, you can sometimes break the infinite recursion by removing the widget in question from one of the config lists (this is what the fix in the readme for zsh-history-substring-search is all about), but it might not be the best workaround for every case (fixing the problems caused by bracketed-paste-magic required setting a separate zstyle). So I think we'll have to come up with workarounds on a case-by-case basis until I can confirm my belief above and we can get PRs merged into all the plugins causing these issues.

@lexinator

sorry to have joined this issue since mine now seems unrelated.

@ericfreese sourcing the scripts in a single run fixed the coredump. The next issue I ran into was https://github.com/solarnz/dotfiles/blob/master/zsh/10-expand-or-complete-with-dots.zsh causing another coredump upon tab. As you said in #107 (comment), the fix is to prefix '.' on the zle functions to avoid recursion.

thanks for the quick reply.

@ericfreese
zsh-users member

I believe v0.2.6 should fix all of these issues without requiring changes to other plugins. Please give that a shot.

Edit: v0.2.6 had a typo. Try v0.2.7

@ericfreese ericfreese closed this Feb 15, 2016
@shangsunset
shangsunset commented Apr 21, 2016 edited

just installed the plugin, crashes still happen upon pressing forward char. I installed as oh-my-zsh plugin

plugins=(git z nvm zsh-syntax-highlighting zsh-autosuggestions)

edit: maybe because i was in tmux?

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