zsh-workers
 help / color / mirror / code / Atom feed
* Commands run from functions don't exit cleanly on terminal close (SIGHUP)?
@ 2012-10-24 14:03 Alan Pinstein
  2012-10-24 14:10 ` Alan Pinstein
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Pinstein @ 2012-10-24 14:03 UTC (permalink / raw)
  To: zsh-workers

I am having issues with ssh sessions not exiting when I closed the terminal window containing them.

I originally noticed this bug while using screen; I believe this bug/problem affects anyone that uses ssh/autossh/tmux/mxrvt/etc from inside a function. It causes screen to hang due to multiple concurrent connections that are orphaned on the client side.

I have reduced the problem down to whether or not the ssh command is executed directly in the shell, or from inside a function.

I isolated the issue from ssh as well; it seems that any command run from inside of a function doesn't cleanly exit when it receives a SIGHUP.

I managed to at least receive the signal before the child exits via TRAPS_ASYNC, but I can't figure out how to make the command die when the trap runs. I've tried "exit" and "return".

The function below reproduces the scenario easily.

willnotdie() {
     echo 'try closing the terminal window while this runs (lasts 10s), notice that the php command is orphaned and does not die'
     echo 'ps ax -o time,ppid,command | grep -v grep| grep "PPID\|php"'
     echo 'if you run the PHP code in this script directly on the CLI, then it exists cleanly on terminal close'

     setopt LOCAL_TRAPS LOCAL_OPTIONS TRAPS_ASYNC
     echo -n "" > ./sig
     (date && echo START) >> ./sig
     trap '(date && echo HUP && exit 1) >> ./sig' HUP
     trap '(date && echo INT) >> ./sig' INT
     php -r '$i = time() + 10; while (true) { if (time() > $i) break; }'
     (date && echo DONE) >> ./sig
}

# monitor the progress with this
while (true) do
ps ax -o time,ppid,command | grep -v grep| grep "PPID\|php"
sleep 1
done

I would appreciate any help.

Thanks in advance.

Alan


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-10-25 14:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-24 14:03 Commands run from functions don't exit cleanly on terminal close (SIGHUP)? Alan Pinstein
2012-10-24 14:10 ` Alan Pinstein
2012-10-25 10:22   ` Peter Stephenson
2012-10-25 11:48     ` Alan Pinstein
2012-10-25 13:22       ` Alan Pinstein
2012-10-25 14:03         ` Peter Stephenson
2012-10-25 14:54         ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).