Skip to content

Commit 43de5e0

Browse files
symphorienmafredri
authored andcommitted
Prevent infinite loop in case of broken zpty file descriptor (#31)
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.
1 parent e6d9372 commit 43de5e0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

async.zsh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,22 @@ _async_zle_watcher() {
306306
local worker=$ASYNC_PTYS[$1]
307307
local callback=$ASYNC_CALLBACKS[$worker]
308308

309+
if [[ -n $2 ]]; then
310+
# from man zshzle(1):
311+
# `hup' for a disconnect, `nval' for a closed or otherwise
312+
# invalid descriptor, or `err' for any other condition.
313+
# Systems that support only the `select' system call always use
314+
# `err'.
315+
316+
# this has the side effect to unregister the broken file descriptor
317+
async_stop_worker $worker
318+
319+
if [[ -n $callback ]]; then
320+
$callback '[async]' 2 "" 0 "$worker:zle -F $1 returned error $2" 0
321+
fi
322+
return
323+
fi;
324+
309325
if [[ -n $callback ]]; then
310326
async_process_results $worker $callback watcher
311327
fi

0 commit comments

Comments
 (0)