Segfault after sourcing zshrc again - conflict with zsh-autosuggestions even when sourced in right order. #126
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
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 -fE) 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.
@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@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
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
Hi, this issue is similar to issue #96:
After opening
zshand sourcing.zshrc, zsh exits with "zsh: segmentation fault zsh":Issue #96 was solved by sourcing
zsh-autosuggestionsbeforezsh-syntax-highlighting, but that solution no longer works. Zsh segfaults no matter their order.Here's the .zshrc file: