Crash when Vim is killed and autocmds are run

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Crash when Vim is killed and autocmds are run

James Vega-3
As one of my users discovered[0], if Vim is killed and autocmds are run
as part of the shutdown, Vim will crash instead of closing gracefully.
From what I can tell, it looks like Vim is exceeding the stack since the
shutdown process (and autocmds) are being run in the context of the
alternate signal stack and that stack is likely only 8k.

This can readily be reproduced using the attached crash.vim.

  $ vim -u crash.vim --noplugin -N
  $ kill $pidOfVim
  Vim: Caught deadly signal TERM
  Vim: Finished.
  Vim: Double signal, exiting

If it is indeed a problem with exceeding the stack, then two possible
solutions seem evident to me.

1) Change the signal handler to simply set a flag that Vim needs to
   exit, return from the signal handler, have another portion of the
   code that checks for that flag (RealWaitForChar ?), and initiate the
   shutdown steps from there.

2) Ignore autocommands if Vim is exiting due to a deadly signal.  Just
   do the minimum necessary steps to gracefully exit -- i.e., flush out
   the swapfiles, viminfo, and quit.

The attached patch does 2) but 1) seems like a more robust (although
potentially more invasive) change.

[0]: http://bugs.debian.org/580961
--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Crash when Vim is killed and autocmds are run

James Vega-3
On Sun, May 23, 2010 at 10:58:55AM -0400, James Vega wrote:
> ...
> This can readily be reproduced using the attached crash.vim.
> ...
> The attached patch does 2) but 1) seems like a more robust (although
> potentially more invasive) change.

Actually attached this time.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[hidden email]>

crash.vim (133 bytes) Download Attachment
dying.diff (1K) Download Attachment
signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Crash when Vim is killed and autocmds are run

Bram Moolenaar
In reply to this post by James Vega-3

James Vega wrote:

> As one of my users discovered[0], if Vim is killed and autocmds are run
> as part of the shutdown, Vim will crash instead of closing gracefully.
> =46rom what I can tell, it looks like Vim is exceeding the stack since the
> shutdown process (and autocmds) are being run in the context of the
> alternate signal stack and that stack is likely only 8k.
>
> This can readily be reproduced using the attached crash.vim.
>
>   $ vim -u crash.vim --noplugin -N
>   $ kill $pidOfVim
>   Vim: Caught deadly signal TERM
>   Vim: Finished.
>   Vim: Double signal, exiting
>
> If it is indeed a problem with exceeding the stack, then two possible
> solutions seem evident to me.
>
> 1) Change the signal handler to simply set a flag that Vim needs to
>    exit, return from the signal handler, have another portion of the
>    code that checks for that flag (RealWaitForChar ?), and initiate the
>    shutdown steps from there.
>
> 2) Ignore autocommands if Vim is exiting due to a deadly signal.  Just
>    do the minimum necessary steps to gracefully exit -- i.e., flush out
>    the swapfiles, viminfo, and quit.
>
> The attached patch does 2) but 1) seems like a more robust (although
> potentially more invasive) change.

Hmm, tricky.

Going back to the original stack will fail in other situations.  Esp.
when something works recursively and we run out of stack space.

Your solution sounds like a reaonable solution.  I'll look into it
later.

--
From "know your smileys":
 <<<:-{    Worf (Never smiles anyways, so he's a bad smiley)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php