Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respawn Pure async worker on crash #543

Merged
merged 6 commits into from
May 1, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Immediately restart worker and relaunch tasks on crash
mafredri committed Apr 13, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 46c0c6d0d38dbf83fed36503285f06ba7ec78223
41 changes: 26 additions & 15 deletions pure.zsh
Original file line number Diff line number Diff line change
@@ -199,6 +199,8 @@ prompt_pure_preprompt_render() {
}

prompt_pure_precmd() {
setopt localoptions noshwordsplit

# Check execution time and store it in a variable.
prompt_pure_check_cmd_exec_time
unset prompt_pure_cmd_timestamp
@@ -379,16 +381,22 @@ prompt_pure_async_renice() {
fi
}

prompt_pure_async_init() {
typeset -g prompt_pure_async_inited
if ((${prompt_pure_async_inited:-0})); then
return
fi
prompt_pure_async_inited=1
async_start_worker "prompt_pure" -u -n
async_register_callback "prompt_pure" prompt_pure_async_callback
async_worker_eval "prompt_pure" prompt_pure_async_renice
}

prompt_pure_async_tasks() {
setopt localoptions noshwordsplit

# Initialize the async worker.
((!${prompt_pure_async_init:-0})) && {
async_start_worker "prompt_pure" -u -n
async_register_callback "prompt_pure" prompt_pure_async_callback
typeset -g prompt_pure_async_init=1
async_job "prompt_pure" prompt_pure_async_renice
}
prompt_pure_async_init

# Update the current working directory of the async worker.
async_worker_eval "prompt_pure" builtin cd -q $PWD
@@ -467,17 +475,20 @@ prompt_pure_async_callback() {

case $job in
\[async])
# Error codes from zsh-async:
# 1 Corrupted worker output.
# 2 ZLE watcher detected an error on the worker fd.
# 3 Response from async_job when worker is missing.
# 130 Async worker exited, this should never happen in
# Pure so the file descriptor is corrupted.
# Handle all the errors that could indicate a crashed
# async worker. See zsh-async documentation for the
# definition of the exit codes.
if (( code == 2 )) || (( code == 3 )) || (( code == 130 )); then
# Our worker died unexpectedly, recovery
# will happen on next prompt.
typeset -g prompt_pure_async_init=0
# Our worker died unexpectedly, try to recover immediately.
# TODO(mafredri): Do we need to handle next_pending
# and defer the restart?
typeset -g prompt_pure_async_inited=0
async_stop_worker prompt_pure
prompt_pure_async_init # Reinit the worker.
prompt_pure_async_tasks # Restart all tasks.

# Reset render state due to restart.
unset prompt_pure_async_render_requested
fi
;;
\[async/eval])