Segfault after sourcing zshrc again - conflict with zsh-autosuggestions even when sourced in right order.
torsava opened this issue Β· 25 comments
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
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
Correct. Tested on 2 separate machines: Arch Linux and Fedora 23.
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.
Thanks!
@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 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!
@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?)
What's happening is this:
- z-asug registered for widget X
- Third party redefines widget X, wrapping z-asug's wrapper
- z-asug re-registers itself for widget X
- Widget X is invoked
- 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.
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
Is there a solution for this ?
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
Is there any solution for this? The workaround doesn't work for me
This workaround does not work for me either. The patch in #150 however does the trick on my system
To everyone who says the workaround #126 (comment) doesn't work for them: note that you need to run make
after applying that patch!
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.
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
Would be great to get a fix for this issue mergedβ¦
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.
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
@zacheryph this workaround works well for me! Perfect!
I believe this is fixed in develop
branch. Give that a shot and let me know if you're still seeing issues with this.
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?
I'm still experiencing a similar problem - starting the shell the first time is no problem, only when I manually source ~/.zshrc
the formatting of suggestion is broken (the same as typed letters). The problem occurs only when using zsh-syntax-highlighting and zsh-autosuggestions together.