Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: A serious bug in execution – where to debug?



On Tue, Jul 30, 2019 at 8:53 PM Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> On Tue, 30 Jul 2019 at 20:22, Roman Perepelitsa
> <roman.perepelitsa@xxxxxxxxx> wrote:
> >
> > Do you think it's possible to implement clean shutdown and reentrant
> > initialization for a piece of code as blackbox?
>
> What do you mean exactly? As a blackbox - as a regular, repeatable method?

In order to implement clean shutdown for a piece of code with
non-trivial capabilities you have to rely on its implementation
details. You cannot implement generic clean shutdown that will work
with any code.

Here's an example. Suppose a plugin you are monitoring spawns a
process. Should you kill it when you unload the plugin? It depends. If
this plugin spawns a process every time it is loaded and kills it
every time you call its public `shutdown` function, then you should
probably kill it to avoid leaking processes. You don't want to have a
horde of stray processes if the plugin is loaded and unloaded multiple
times. On the other hand, if this plugin spawns a one-per-user daemon
(could also be one-per-machine), then another shell might already be
using it, and if you kill the daemon when the plugin is unloaded in
one shell, you can break that same plugin in another shell. Plugins
don't expect that their internal processes will be randomly killed,
files randomly deleted and internal variables randomly unset, so if
you start doing it, things will break. To implement clean shutdown in
this case, you need to check whether this plugin is the last instance
for this user/machine and only then kill the daemon. In other words,
in both cases you need to implement the same logic the plugin already
implements in its shutdown routine. Once you implement it, you have to
keep it in sync with internal implementation changes of the plugin.

Roman.



Messages sorted by: Reverse Date, Date, Thread, Author