Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: never unregister important hooks and maintain hook semantics…
… in shutdown Here important-plugin implies `important hook`. Before this commit, when in shutdown: - existing in-flight hooks where abandoned, cutting the hook-chain and never call hook_final_cb - hooks where removed when its plugin died, even important-plugin because `shutdown` overrules - but hook events can be called while waiting for plugins to self-terminate (up to 30s) and subdaemons still alive and it looks as if no plugin ever registered the hook. After this commit, when in shutdown: - existing in-flight hook (chains) are honoured and can finalize, same semantics as LD_STATE_RUNNING - important-plugins are kept alive until after shutdown_subdaemons, so they don't miss hooks - JSON RPC commands are functional, but anything unimportant-plugin related cannot be relied on TODO: - Run tests -> hangs forever on test_closing, so skip them - Q. Does this open a can of worms or races when (normal) plugins with hooks die randomly? A. Yes, for example htlc_accepted calls triggers hook invoice_payment, but plugin (fetchinvoice?) already died ** * CONCLUSION: If you want to give more control over shutdown, I think there could be * a plugin `shutdown_clean.py` with RPC method `shutdown_clean`. When called, that * plugin starts additional (important) plugin(s) that register relevant hooks and, for example, hold-off * new htcl's and wait for existing inflight htlc's to resolve ... and finally call RPC `stop`. * * Note: --important-plugin only seems to work at start, not via `plugin start shutdown_clean.py` * maybe we can add? Or do something with disable? * * Some parts of this commit is stil good, i.e. hook semantics of important plugins should be consistent * untill the very last potential hook call. ** - What if important-plugin dies unexpectatly and lightningd_exit() calls io_break() is that bad? - What are the benefits? Add example where on shutdown inflight htlc's are resolved/cleared and new htlc's blocked, see ElementsProject#4842 - Split commit into hook-related stuff and others, for clarity of reasoning - Q. How does this relate (hook-wise) to db_write plugins? A. Looks like this hook is treated like any other hook: when plugin dies, hook is removed, so to be safe backup needs to be `important`. Hook documentation does not mention `important-plugin` but BACKUP.md does. TODO: Tested this -> `plugin stop backup.py` -> "plugin-backup.py: Killing plugin: exited during normal operation" In fact, running current backup.py with current master misses a couple of writes in shutdown (because its hook is removed, see issue ElementsProject#4785).
- Loading branch information