zsh-users/zsh-syntax-highlighting

zsh crash when reload `~/.zshrc`

dozer47528 opened this issue ยท 25 comments

  1. Open the Terminal
  2. Run source ~/.zshrc
  3. Process completed

screen shot 2016-04-01 at 16 16 12

What's the output of echo $ZSH_VERSION $ZSH_HIGHLIGHT_VERSION $ZSH_HIGHLIGHT_REVISION?

Does this happen if you do zsh -f and therein run repeat 2 source /path/to/.../zsh-syntax-highlighting.zsh?

echo $ZSH_VERSION $ZSH_HIGHLIGHT_VERSION $ZSH_HIGHLIGHT_REVISION
5.0.8 0.5.0-dev HEAD

And it doesn't happen when I use zsh -f

Here is my plugins list:
extract z git git-extras git-flow gitignore mvn bundler bower gitfast github npm vagrant python pip pyenv docker zsh-autosuggestions zsh-completions zsh_reload brew brew-cask zsh-syntax-highlighting

Please provide a minimal reproduction recipe. (That is: bisect your dotfiles down to a minimum that still reproduces the problem, and has as few external dependencies as possible.)

Does "[Process completed]" mean zsh exited with a segfault / bus error? In this case, try zsh 5.2.

(I assume you understand what I'm asking, but ask if anything is unclear.)

this my minimal .zshrc file can cause the problem:

ZSH=$HOME/.oh-my-zsh
ZSH_THEME="ys"

plugins=(zsh-autosuggestions zsh-syntax-highlighting)
source $ZSH/oh-my-zsh.sh

There are some conflicts between zsh-autosuggestions and zsh-syntax-highlighting

And I try to manually reload this two plugins like this:

  • source zsh-autosuggestions.plugin.zsh : nothing happens
    source zsh-syntax-highlighting.plugin.zsh : crash

The zsh-syntax-highlighting.plugin.zsh plugin will cause the problem.

And my zsh is the newest version from Homebrew.

Could you run set -x before the second source z-sy-h.zsh command? What's the last command before it aborts?

Do you use zsh 5.2? It's not clear from what you said whether you use 5.0.8 or 5.2.

kuoe0 commented

I have the same problem!

Step to produce:

~% zsh
~% source ~/.zshrc
~% [1]    26129 segmentation fault  zsh

My .zshrc:

source $HOME/.antigen/antigen.zsh
antigen use oh-my-zsh
antigen bundle zsh-users/zsh-autosuggestions
antigen bundle zsh-users/zsh-syntax-highlighting
antigen apply

My environment:

~% zsh --version
zsh 5.2 (x86_64-apple-darwin14.5.0)

~%  sw_vers        
ProductName:    Mac OS X
ProductVersion: 10.10.5
BuildVersion:   14F1713

Diagnosis and proposed fixes in #294.

Related discussion in zsh-autosuggestions: zsh-users/zsh-autosuggestions#126

kuoe0 commented

That's great!! And I also test the same config on Ubuntu 14.04. It works without crash. Hope this info help you. ๐Ÿ‘

@kuoe0 to clarify: you use the same .zshrc on Ubuntu 14.04 and on OS X 10.10, and the crash reproduces only on the latter? For reference, what version of zsh do you use on the former?

kuoe0 commented

Sorry for the unclear info. There is the zsh and system info following:

~% zsh --version
zsh 5.0.2 (x86_64-pc-linux-gnu)

~% cat /etc/linuxmint/info
RELEASE=17.2
CODENAME=rafaela
EDITION="Cinnamon 64-bit"
DESCRIPTION="Linux Mint 17.2 Rafaela"
DESKTOP=Gnome
TOOLKIT=GTK
NEW_FEATURES_URL=http://www.linuxmint.com/rel_rafaela_cinnamon_whatsnew.php
RELEASE_NOTES_URL=http://www.linuxmint.com/rel_rafaela_cinnamon.php
USER_GUIDE_URL=help:linuxmint
GRUB_TITLE=Linux Mint 17.2 Cinnamon 64-bit

I've proposed to zsh-autosuggestions a patch that fixes the problem: zsh-users/zsh-autosuggestions#126 (comment)

Setting labels: "Upstream" because the root problem is in z-asug (it blindly wraps a non-z-asug widget that wraps a z-asug widget) and "Bug" because of the segfault symptom.

I caught this in gdb earlier, the backtrace was a loop of:

_zsh_autosuggest_invoke_original_widget
_zsh_autosuggest_modify
_zsh_autosuggest_widget_modify
_zsh_autosuggest_bound_self-insert
_zsh_highlight_call_widget
_zsh_highlight_widget_self-insert

Is this the same issue? It does not crash, but I can't do anything.
screenshot 2016-05-18 at 4 29 52 pm

Is this the same issue? It does not crash, but I can't do anything.

That's plausible, see zsh-users/zsh-autosuggestions#126 (comment). Does the patch posted two comments above it fix your symptoms? (If not, please open a new issue and we can debug further there.)

No it did not, opened #322

Note that you need to run make after applying zsh-users/zsh-autosuggestions#126 (comment).

I assume you'll find that if you run apply that patch and make, the problem disappears... the other option would be that we have two independent segfault bugs here, but Occam's razor says that's not the case.

Closing. The known problem in z-asug has known workarounds. No other problem was identified.

I added this to my .zshrc

if [[ $ZSH_EVAL_CONTEXT == 'file' ]]; then
	printf "autosuggestions loaded"
  source "./.zsh/zsh-autosuggestions/zsh-autosuggestions.zsh"
  source "./.zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
fi

This fixed my terminal from crashing.

this if statement will only run when a new window is open and wont get triggered

Appear again on macOS Sierra

~ echo $ZSH_VERSION; echo $ZSH_HIGHLIGHT_VERSION; echo $ZSH_HIGHLIGHT_REVISION           
5.2
0.6.0-dev
HEAD

@garrettmac 's workaround works. Need to remove zsh-syntax-highlighting from plugins config.

@garrettmac, i think that need for sourcing when load from compiled .zwc, in my case:

if [[ $ZSH_EVAL_CONTEXT == 'file' ]] || [[ $ZSH_EVAL_CONTEXT == 'filecode' ]]; then
    source "${ZSH_CUSTOM}/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh"
fi

@popstas How about if (( ZSHRC_LOAD_ONCE++ == 0 )); then source โ€ฆ; fi? No need to declare $ZSHRC_LOAD_ONCE either before or after.

zsh-users/zsh-autosuggestions#126 has been fixed on zsh-autosuggestions' develop branch; anyone still seeing issues please update z-asug. Thanks.

@danielshahaf , thank you, your workaround nicer! Will watching for zsh-autosuggestions releases.