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

iTerm2 crashes #107

Closed
thenitai opened this issue Feb 7, 2016 · 19 comments
Closed

iTerm2 crashes #107

thenitai opened this issue Feb 7, 2016 · 19 comments

Comments

@thenitai
Copy link

thenitai commented Feb 7, 2016

(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
Copy link

kergoth commented Feb 11, 2016

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
Copy link

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

@ericfreese
Copy link
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
Copy link

kergoth commented Feb 14, 2016

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

@ericfreese
Copy link
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
Copy link

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
Copy link
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
Copy link
Member

Thanks @lexinator I'll look into this.

@lexinator
Copy link

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
Copy link

kergoth commented Feb 14, 2016

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
Copy link
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
Copy link
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
Copy link

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
Copy link
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

@shangsunset
Copy link

shangsunset commented Apr 21, 2016

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?

dritter added a commit to dritter/powerlevel9k that referenced this issue Jan 2, 2017
@ghost
Copy link

ghost commented Mar 13, 2017

I have the same problem.
My ~/.zshrc looks like this:
...
antigen bundle zsh-users/zsh-syntax-highlighting
antigen bundle zsh-users/zsh-autosuggestions
...

Every time I do source ~/.zshrc, the next key press make iterm crash.

If I comment one of the above lines, the problem is gone.

@kylealwyn
Copy link

Same issue with iTerm2. Removing zsh-autosuggestions from plugins resolves issue.

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

@ericfreese
Copy link
Member

ericfreese commented Mar 20, 2017

@MikeBailleul @kylealwyn Please try the develop branch. What you were likely seeing was issue #166, which has been fixed on the develop branch but not yet on master.

@ghost
Copy link

ghost commented Mar 20, 2017

Awesome, thanks.

laggardkernel added a commit to laggardkernel/fzf-marks that referenced this issue Apr 10, 2020
Recalling precmd_functions is only needed when cwd is changed, which
means when `jump` is called.

`.reset-prompt`: bypass the zsh-syntax-highlighting wrapper<Paste>
- sorin-ionescu/prezto#1026
- zsh-users/zsh-autosuggestions#107 (comment)

`-R`: redisplay the prompt to avoid old prompts being eaten up
- Powerlevel9k/powerlevel9k#1176 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants