Segfault after sourcing zshrc again - conflict with zsh-autosuggestions even when sourced in right order. #126

Open
torsava opened this Issue Feb 24, 2016 · 11 comments

6 participants

@torsava

Hi, this issue is similar to issue #96:
After opening zsh and sourcing .zshrc, zsh exits with "zsh: segmentation fault zsh":

% zsh
% . ~/.zshrc
zsh: segmentation fault  zsh

Issue #96 was solved by sourcing zsh-autosuggestions before zsh-syntax-highlighting, but that solution no longer works. Zsh segfaults no matter their order.
Here's the .zshrc file:

source ~/bin/zsh/antigen/antigen.zsh
antigen bundle tarruda/zsh-autosuggestions
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply
@ericfreese
zsh-users member

This is only when sourcing the .zshrc for the second time correct?

I.e. You don't get a segfault if you do this?

% zsh -f
% . ~/.zshrc
@ericfreese ericfreese added the bug label Feb 24, 2016
@tomparys

Correct. Tested on 2 separate machines: Arch Linux and Fedora 23.

@ericfreese
zsh-users member

I've been experimenting a bit.

Some test cases:

A) Sourcing only this plugin multiple times (no segfault)

% zsh -f
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% # no segfaults here...

B) Sourcing only the zsh-syntax-highlighting plugin multiple times (no segfault)

% git -C ~/Code/zsh-syntax-highlighting rev-parse --short HEAD
7044c19
% zsh -f
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% # no segfaults here...

C) Sourcing zsh-syntax-highlighting multiple times, then this plugin multiple times (no segfault)

% zsh -f
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% # no segfaults here...

D) Sourcing this plugin (any number of times), then zsh-syntax-highlighting (segfault)

% zsh -f
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh
%% source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% zsh: segmentation fault  zsh -f

E) Sourcing both plugins at the same command prompt (see #107 (comment)) (no segfault)

% zsh -f
%% source ~/Code/zsh-autosuggestions/zsh-autosuggestions.zsh; source ~/Code/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
%% # no segfaults here...

So, yes there is some sort of bug here. I'll look into exactly what triggers these segfaults and see if there's something we can do in this plugin to avoid them.

In the mean time, the obvious workaround is to not source these plugins at different prompts. Just put them in your .zshrc and only source them once. Start a new terminal session when making changes to your config instead of sourcing your .zshrc again.

@tomparys

Thanks!

@danielshahaf

@ericfreese Hi, z-sy-h maintainer here. I've been getting reports of this too; let me know if you find that a fix is needed on my side.

@danielshahaf

@ericfreese The following patch fixes the problem for me and keeps both z-asug and z-sy-h working. Why does z-asug reinstall itself at every precmd?

diff --git a/src/start.zsh b/src/start.zsh
index 54f5bb8..fc3a7cd 100644
--- a/src/start.zsh
+++ b/src/start.zsh
@@ -7,6 +7,7 @@
 _zsh_autosuggest_start() {
        _zsh_autosuggest_check_deprecated_config
        _zsh_autosuggest_bind_widgets
+       add-zsh-hook -d precmd _zsh_autosuggest_start
 }

 autoload -Uz add-zsh-hook
@danielshahaf

@ericfreese We can go over this by IRC if you want — we're at #zsh-syntax-highlighting on freenode. (Doesn't seem like z-asug has a channel?)

@danielshahaf

What's happening is this:

  1. z-asug registered for widget X
  2. Third party redefines widget X, wrapping z-asug's wrapper
  3. z-asug re-registers itself for widget X
  4. Widget X is invoked
  5. z-asug's "new" wrapper is invoked, and calls the third-party wrapper, which calls z-asug's "old" wrapper, which calls the third-party wrapper again.

That is: the wrapper installed at (1) invokes the meaning of X immediately prior to (3). If the wrapper installed at (3) invoked the meaning of X immediately prior to (3) and the wrapper installed at (1) invoked the meaning of X immediately prior to (1), the infinite loop would not occur.

@danielshahaf

Minimal reproducer (/cc @phy1729):

# source zsh-autosuggestions.zsh 
# eval "my-self-insert() { zle -M 'foobar'; ${(q)widgets[self-insert]#*:} \"\$@\" }" 
# zle -N self-insert my-self-insert 
# 
Segmentation fault
@rgcr

Is there a solution for this ?

@luizdepra
luizdepra commented Jul 18, 2016 edited

Same problem here. I'm using zplug, and changing load order does nothing.

export ZPLUG_HOME=~/.zplug
source ~/.zplug/init.zsh

zplug "plugins/git", from:oh-my-zsh, nice:10
zplug "zsh-users/zsh-completions"
zplug "zsh-users/zsh-autosuggestions", nice:18
zplug "zsh-users/zsh-syntax-highlighting", nice:17
zplug "zsh-users/zsh-history-substring-search", nice:19

zplug "robbyrussell/oh-my-zsh"
setopt prompt_subst
zplug "caiogondim/bullet-train-oh-my-zsh-theme", use:bullet-train.zsh-theme

if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    fi
fi

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