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

Closed
torsava opened this Issue Feb 24, 2016 · 24 comments

Comments

@torsava

torsava commented Feb 24, 2016

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

This comment has been minimized.

Show comment
Hide comment
@ericfreese

ericfreese Feb 24, 2016

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
Member

ericfreese commented Feb 24, 2016

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

This comment has been minimized.

Show comment
Hide comment
@tomparys

tomparys Feb 24, 2016

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

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

@ericfreese

This comment has been minimized.

Show comment
Hide comment
@ericfreese

ericfreese Feb 24, 2016

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.

Member

ericfreese commented Feb 24, 2016

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

This comment has been minimized.

Show comment
Hide comment

Thanks!

@danielshahaf

This comment has been minimized.

Show comment
Hide comment
@danielshahaf

danielshahaf Apr 22, 2016

@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.

@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

This comment has been minimized.

Show comment
Hide comment
@danielshahaf

danielshahaf May 4, 2016

@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

edit (to users who want to test this patch): Remember to run make after applying this patch!

danielshahaf commented May 4, 2016

@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

edit (to users who want to test this patch): Remember to run make after applying this patch!

@danielshahaf

This comment has been minimized.

Show comment
Hide comment
@danielshahaf

danielshahaf May 4, 2016

@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?)

@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

This comment has been minimized.

Show comment
Hide comment
@danielshahaf

danielshahaf May 5, 2016

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.

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

This comment has been minimized.

Show comment
Hide comment
@danielshahaf

danielshahaf May 5, 2016

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

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

This comment has been minimized.

Show comment
Hide comment
@rgcr

rgcr Jul 17, 2016

Is there a solution for this ?

rgcr commented Jul 17, 2016

Is there a solution for this ?

@luizdepra

This comment has been minimized.

Show comment
Hide comment
@luizdepra

luizdepra Jul 18, 2016

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

luizdepra commented Jul 18, 2016

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
@bayan9

This comment has been minimized.

Show comment
Hide comment
@bayan9

bayan9 Sep 26, 2016

Is there any solution for this? The workaround doesn't work for me

bayan9 commented Sep 26, 2016

Is there any solution for this? The workaround doesn't work for me

@jackgu1988 jackgu1988 referenced this issue in zsh-users/zsh-syntax-highlighting Sep 30, 2016

Closed

Terminal crush after source #370

@patrick96

This comment has been minimized.

Show comment
Hide comment
@patrick96

patrick96 Sep 30, 2016

This workaround does not work for me either. The patch in #150 however does the trick on my system

This workaround does not work for me either. The patch in #150 however does the trick on my system

@danielshahaf

This comment has been minimized.

Show comment
Hide comment
@danielshahaf

danielshahaf Oct 18, 2016

To everyone who says the workaround #126 (comment) doesn't work for them: note that you need to run make after applying that patch!

To everyone who says the workaround #126 (comment) doesn't work for them: note that you need to run make after applying that patch!

@molovo

This comment has been minimized.

Show comment
Hide comment
@molovo

molovo Oct 19, 2016

Can confirm, #150 resolves this issue.

molovo commented Oct 19, 2016

Can confirm, #150 resolves this issue.

@josefson

This comment has been minimized.

Show comment
Hide comment
@josefson

josefson Oct 19, 2016

I just tried #150, which didn't work for me. Then i tried #126 comment and it worked. Thank you both for trying out solutions.

josefson commented Oct 19, 2016

I just tried #150, which didn't work for me. Then i tried #126 comment and it worked. Thank you both for trying out solutions.

@devnall

This comment has been minimized.

Show comment
Hide comment
@devnall

devnall Nov 4, 2016

Both #150 and @danielshahaf 's patch were successful in resolving this issue for me.

BTW running make after applying @danielshahaf 's patch only adds
add-zsh-hook -d precmd _zsh_autosuggest_start
on line 477 in zsh-autosuggestions.zsh; updating the patch to add that one extra line may be easier than reminding people to run make

devnall commented Nov 4, 2016

Both #150 and @danielshahaf 's patch were successful in resolving this issue for me.

BTW running make after applying @danielshahaf 's patch only adds
add-zsh-hook -d precmd _zsh_autosuggest_start
on line 477 in zsh-autosuggestions.zsh; updating the patch to add that one extra line may be easier than reminding people to run make

@caesar

This comment has been minimized.

Show comment
Hide comment
@caesar

caesar Dec 19, 2016

Would be great to get a fix for this issue merged…

caesar commented Dec 19, 2016

Would be great to get a fix for this issue merged…

@zacheryph

This comment has been minimized.

Show comment
Hide comment
@zacheryph

zacheryph Feb 7, 2017

Can there just be a check put in that prevents this from sourcing 'itself' if its already been sourced? Doesn't seem like any other "solution" is anywhere near fruition. Almost a year old here.

Can there just be a check put in that prevents this from sourcing 'itself' if its already been sourced? Doesn't seem like any other "solution" is anywhere near fruition. Almost a year old here.

@zacheryph

This comment has been minimized.

Show comment
Hide comment
@zacheryph

zacheryph Feb 7, 2017

For any/all that continue to have problems with this. This is my work around. NOTE that I am using oh-my-zsh with repos loaded in .oh-my-zsh/custom/plugins

plugins=(all your normal plugins here)

if [ -z "$_zsh_custom_scripts_loaded" ]; then
  _zsh_custom_scripts_loaded=1
  plugins+=(zsh-autosuggestions zsh-syntax-highlighting)
fi

For any/all that continue to have problems with this. This is my work around. NOTE that I am using oh-my-zsh with repos loaded in .oh-my-zsh/custom/plugins

plugins=(all your normal plugins here)

if [ -z "$_zsh_custom_scripts_loaded" ]; then
  _zsh_custom_scripts_loaded=1
  plugins+=(zsh-autosuggestions zsh-syntax-highlighting)
fi
@seagle0128

This comment has been minimized.

Show comment
Hide comment
@seagle0128

seagle0128 Feb 10, 2017

@zacheryph this workaround works well for me! Perfect!

seagle0128 commented Feb 10, 2017

@zacheryph this workaround works well for me! Perfect!

ericfreese added a commit that referenced this issue Feb 18, 2017

@ericfreese

This comment has been minimized.

Show comment
Hide comment
@ericfreese

ericfreese Feb 18, 2017

Member

I believe this is fixed in develop branch. Give that a shot and let me know if you're still seeing issues with this.

Member

ericfreese commented Feb 18, 2017

I believe this is fixed in develop branch. Give that a shot and let me know if you're still seeing issues with this.

@ericfreese ericfreese closed this Feb 18, 2017

@ericfreese ericfreese referenced this issue Feb 19, 2017

Merged

v0.4.0 #218

12 of 13 tasks complete

ericfreese added a commit that referenced this issue Feb 28, 2017

Fix issues with widgets wrapped by other plugins
Puts in a better fix for #126 and related issues.

ericfreese added a commit that referenced this issue Mar 3, 2017

Fix issues with widgets wrapped by other plugins
Puts in a better fix for #126 and related issues.

ericfreese added a commit that referenced this issue Mar 3, 2017

Fix issues with widgets wrapped by other plugins
Puts in a better fix for #126 and related issues.
@kreedz

This comment has been minimized.

Show comment
Hide comment
@kreedz

kreedz Mar 22, 2017

Yeah!
This works well:

zplug "zsh-users/zsh-autosuggestions", at:develop
zplug "zsh-users/zsh-syntax-highlighting", defer:3

When to expect this in master?

kreedz commented Mar 22, 2017

Yeah!
This works well:

zplug "zsh-users/zsh-autosuggestions", at:develop
zplug "zsh-users/zsh-syntax-highlighting", defer:3

When to expect this in master?

@ericfreese

This comment has been minimized.

Show comment
Hide comment
@ericfreese

ericfreese Mar 23, 2017

Member

When to expect this in master?

Relatively soon ;)

PR to watch is #218

Member

ericfreese commented Mar 23, 2017

When to expect this in master?

Relatively soon ;)

PR to watch is #218

@poupougnac poupougnac referenced this issue in junegunn/fzf Apr 11, 2017

Closed

Installation with ZSH, segmentation fault ERROR #904

2 of 15 tasks complete

seagle0128 added a commit to seagle0128/dotfiles that referenced this issue May 13, 2017

Remove workaround.
zsh-autosuggestions 0.4.0: Gracefully handle being sourced multiple times (#126).
zsh-users/zsh-autosuggestions#126.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment