Skip to content

plugins: db_write hook and safe shutdown, back to square one? #5859

Open
@SimonVrouwe

Description

@SimonVrouwe

By change chance I discovered that lightningd's shutdown sequence has been changed again in #5577, which seems to partly revert the effects of #4897 and #4959.

#4897 and #4959 where carefully crafted to guarantee that no database write can occur after plugins are shutdown, so that a backup plugin could never miss db_write hook calls.

Most notably e7fe59b moves closing of the database back to the bottom again, breaking that guarantee.

/* Tell plugins we're shutting down, use force if necessary. */
shutdown_plugins(ld);
/* Now kill any remaining connections */
jsonrpc_stop_all(ld);
/* Get rid of major subdaemons. */
shutdown_global_subdaemons(ld);
/* Clean up internal peer/channel/htlc structures. */
free_all_channels(ld);
/* Now close database */
ld->wallet->db = tal_free(ld->wallet->db);

In my opinion this makes use of backup.py plugin unsafe (again).

@rustyrussell Why the change?

#5577 mentions an issue, but has no further reference, about:

bookkeeper gets upset that its commands are rejected during shutdown

Seriously?

edit Above issue with the db_write hook also applies in general to other hooks. When plugins are freed during shutdown their hooks are unregistered and one expects that these hooks cannot be called after that (i.e. that lightningd is sufficiently dead), this was the case before e7fe59b. Now some subdaemons are kept alive longer, for example connectd happily accepts incoming connections during the 30s shutdown window. But any plugin that registered the peer_connected hook and maybe would reject the peer, is gone!

This was already discussed in #4883 and so the answer to the title seems (sadly) 'Yes'.
How unsafe is it? I don't know, missing a peer_connected hook doesn't seem very harmful, just ugly and inconsistent. What about other hooks? And why is hsmd still running, will it sign anything?

So far no response from the author of e7fe59b, perhaps @niftynei can help me out what the issues where with bookkeeper before that commit?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions