Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add early abort in case of misconfigured plugins #4418

Merged
merged 2 commits into from
Mar 10, 2021

Conversation

cdecker
Copy link
Member

@cdecker cdecker commented Mar 9, 2021

There are ways to misconfigure plugins that will cause us to shut
down. These include having an important plugin fight for a method name
with another plugin, e.g., by loading the same plugin twice. Until now
we would happily continue with the startup sequence only to later
realize that we were supposed to shutdown, but by then we'd have
buried the error message in the logs.

This PR just adds a check for misconfigurations before we even start
the normal io_loop, avoiding expensive initializations and not
hiding the log entries about the cause. This works if we're just using
--help as well, and produces a much clearer picture of what is going
on.

I also added the name of the plugin that was clashing with RPC methods.

Fixes #4415
Reported-by: PsySc0rpi0n
Reported-by: Ján Sáreník <@jsarenik>

We were reporting the failure immediately but still continuing with
the startup. This could happen if an important plugin ends up in a
race with another plugin (important or not) for a contended
resource (CLI option or RPC method name). We would eventually notice
that we were supposed to abort, but at that point we already processed
a couple of blocks, loaded the entire state, etc.

This just aborts early with a sane error message.

Changelog-Added: plugin: If there is a misconfiguration with important plugins we now abort early with a more descriptive error message.

Reported-by: PsySc0rpi0n
Reported-by: Ján Sáreník <@jsarenik>
@cdecker cdecker changed the title Plugin misconfig Add early abort in case of misconfigured plugins Mar 9, 2021
@jsarenik
Copy link
Collaborator

jsarenik commented Mar 9, 2021

Thank you @cdecker!

Currently it hangs which is pretty good because it would not infinitely restart on systemd/daemontools setups:

$ lightningd --testnet --plugin=/tmp/backup/backup.py --plugin=$HOME/src/plugins/backup/backup.py
...
2021-03-09T10:44:34.704Z DEBUG   plugin-manager: started(42331) /tmp/backup/backup.py
2021-03-09T10:44:34.713Z DEBUG   plugin-manager: started(42332) /home/nsm/src/plugins/backup/backup.py
2021-03-09T10:44:34.795Z UNUSUAL plugin-backup.py: Killing plugin: Could not register method "backup-compact", a method with that name is already registered by plugin /tmp/backup/backup.py
^C

UPDATE: NACK 7bafc57 (see below)

@jsarenik
Copy link
Collaborator

jsarenik commented Mar 9, 2021

What do others think? Would you prefer a hanging lightningd or should it rather exit (returning something bigger than 0)?

* effort in starting up.
*/
if (ld->exit_code)
fatal("Could not initialize the plugins, see above for details.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdecker seemingly I never get here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I thought that important flag is set in plugin details automatically. All good now. Thank you.

@cdecker
Copy link
Member Author

cdecker commented Mar 9, 2021

That's strange, it doesn't hang when I test it locally. Hanging is definitely the wrong thing to do here.

@cdecker
Copy link
Member Author

cdecker commented Mar 9, 2021

Notice that we don't exit if a non-important plugin dies. Please use --important-plugin instead @jsarenik, I expect your test is actually starting correctly but not printing anything since you have --log-level=info and it's actually working fine.

@jsarenik
Copy link
Collaborator

@cdecker Thanks for info. --important-plugin really helps. By the way I have log-lever=debug, just cherry-picking when pasting here.

$ lightningd --testnet --important-plugin=/tmp/backup/backup.py --important-plugin=$HOME/src/plugins/backup/backup.py
...
$ ~/service/lightningd-testnet-esplora/run 
2021-03-10T17:22:53.769Z DEBUG   plugin-manager: blacklist for bcli
2021-03-10T17:22:53.769Z INFO    plugin-manager: /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/bcli: disabled via disable-plugin
2021-03-10T17:22:53.769Z DEBUG   plugin-manager: blacklist for bcli
2021-03-10T17:22:53.769Z INFO    plugin-manager: /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/bcli: disabled via disable-plugin
2021-03-10T17:22:53.770Z DEBUG   plugin-manager: started(38680) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/autoclean
2021-03-10T17:22:53.771Z DEBUG   plugin-manager: started(38681) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/fetchinvoice
2021-03-10T17:22:53.772Z DEBUG   plugin-manager: started(38682) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/keysend
2021-03-10T17:22:53.773Z DEBUG   plugin-manager: started(38683) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/offers
2021-03-10T17:22:53.782Z DEBUG   plugin-manager: started(38684) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/pay
2021-03-10T17:22:53.790Z DEBUG   plugin-manager: started(38685) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/txprepare
2021-03-10T17:22:53.796Z DEBUG   plugin-manager: started(38686) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/spenderp
2021-03-10T17:22:53.806Z DEBUG   plugin-manager: started(38687) /home/nsm/lightning-my/bin/../libexec/c-lightning/plugins/esplora
2021-03-10T17:22:53.814Z DEBUG   plugin-manager: started(38688) /tmp/backup/backup.py
2021-03-10T17:22:53.823Z DEBUG   plugin-manager: started(38689) /home/nsm/src/plugins/backup/backup.py
2021-03-10T17:22:53.838Z INFO    plugin-esplora: getutxout
2021-03-10T17:22:53.924Z UNUSUAL plugin-backup.py: Killing plugin: Could not register method "backup-compact", a method with that name is already registered by plugin /tmp/backup/backup.py
2021-03-10T17:22:53.924Z **BROKEN** plugin-backup.py: Plugin marked as important, shutting down lightningd!
Could not initialize the plugins, see above for details.

ACK 7bafc57

* effort in starting up.
*/
if (ld->exit_code)
fatal("Could not initialize the plugins, see above for details.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I thought that important flag is set in plugin details automatically. All good now. Thank you.

Copy link
Collaborator

@niftynei niftynei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 7bafc57

@niftynei niftynei merged commit 0bc8a47 into ElementsProject:master Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Doubly-loaded plugins
3 participants