Skip to content

Commit

Permalink
Prevent infinite loop in case of broken zpty file descriptor (#31)
Browse files Browse the repository at this point in the history
In some cases, the fd created by zpty can become corrupted: if the other
end was disconnected, if the fd was closed and so on.
If we ignore this condition, then we enter a infinite loop.

Instead, when the fd becomes invalid, unregister the corresponding
worker and notify the callback.
  • Loading branch information
symphorien authored and mafredri committed Dec 14, 2018
1 parent e6d9372 commit 43de5e0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions async.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,22 @@ _async_zle_watcher() {
local worker=$ASYNC_PTYS[$1]
local callback=$ASYNC_CALLBACKS[$worker]

if [[ -n $2 ]]; then
# from man zshzle(1):
# `hup' for a disconnect, `nval' for a closed or otherwise
# invalid descriptor, or `err' for any other condition.
# Systems that support only the `select' system call always use
# `err'.

# this has the side effect to unregister the broken file descriptor
async_stop_worker $worker

if [[ -n $callback ]]; then
$callback '[async]' 2 "" 0 "$worker:zle -F $1 returned error $2" 0
fi
return
fi;

if [[ -n $callback ]]; then
async_process_results $worker $callback watcher
fi
Expand Down

0 comments on commit 43de5e0

Please sign in to comment.