mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
lightningd: give option to crash if a subdaemon fails.
Either when it exits with a signal, or sends an error status message. Then we make test_lightningd.py use it. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
64a26b06e7
commit
ec63c0d10b
4 changed files with 19 additions and 0 deletions
|
@ -112,6 +112,9 @@ struct lightningd {
|
||||||
/* If we have a --dev-disconnect file */
|
/* If we have a --dev-disconnect file */
|
||||||
int dev_disconnect_fd;
|
int dev_disconnect_fd;
|
||||||
|
|
||||||
|
/* If we have --dev-fail-on-subdaemon-fail */
|
||||||
|
bool dev_subdaemon_fail;
|
||||||
|
|
||||||
/* HTLCs in flight. */
|
/* HTLCs in flight. */
|
||||||
struct htlc_in_map htlcs_in;
|
struct htlc_in_map htlcs_in;
|
||||||
struct htlc_out_map htlcs_out;
|
struct htlc_out_map htlcs_out;
|
||||||
|
|
|
@ -239,6 +239,8 @@ static void dev_register_opts(struct lightningd *ld)
|
||||||
{
|
{
|
||||||
opt_register_noarg("--dev-no-broadcast", opt_set_bool,
|
opt_register_noarg("--dev-no-broadcast", opt_set_bool,
|
||||||
&ld->topology->dev_no_broadcast, opt_hidden);
|
&ld->topology->dev_no_broadcast, opt_hidden);
|
||||||
|
opt_register_noarg("--dev-fail-on-subdaemon-fail", opt_set_bool,
|
||||||
|
&ld->dev_subdaemon_fail, opt_hidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct config testnet_config = {
|
static const struct config testnet_config = {
|
||||||
|
|
|
@ -318,6 +318,9 @@ static void subdaemon_malformed_msg(struct subd *sd, const u8 *msg)
|
||||||
tal_hexstr(msg,
|
tal_hexstr(msg,
|
||||||
msg + sizeof(be16),
|
msg + sizeof(be16),
|
||||||
tal_count(msg) - sizeof(be16)));
|
tal_count(msg) - sizeof(be16)));
|
||||||
|
|
||||||
|
if (sd->ld->dev_subdaemon_fail)
|
||||||
|
fatal("Subdaemon %s sent malformed message", sd->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns true if logged, false if malformed. */
|
/* Returns true if logged, false if malformed. */
|
||||||
|
@ -361,6 +364,10 @@ log_str_peer:
|
||||||
/* Shouldn't happen. */
|
/* Shouldn't happen. */
|
||||||
log_str_broken:
|
log_str_broken:
|
||||||
log_broken(sd->log, "%s: %.*s", name, str_len, str);
|
log_broken(sd->log, "%s: %.*s", name, str_len, str);
|
||||||
|
|
||||||
|
if (sd->ld->dev_subdaemon_fail)
|
||||||
|
fatal("Subdaemon %s hit error", sd->name);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,12 +451,14 @@ next:
|
||||||
static void destroy_subd(struct subd *sd)
|
static void destroy_subd(struct subd *sd)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
bool fail_if_subd_fails = sd->ld->dev_subdaemon_fail;
|
||||||
|
|
||||||
switch (waitpid(sd->pid, &status, WNOHANG)) {
|
switch (waitpid(sd->pid, &status, WNOHANG)) {
|
||||||
case 0:
|
case 0:
|
||||||
log_debug(sd->log, "Status closed, but not exited. Killing");
|
log_debug(sd->log, "Status closed, but not exited. Killing");
|
||||||
kill(sd->pid, SIGKILL);
|
kill(sd->pid, SIGKILL);
|
||||||
waitpid(sd->pid, &status, 0);
|
waitpid(sd->pid, &status, 0);
|
||||||
|
fail_if_subd_fails = false;
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
log_unusual(sd->log, "Status closed, but waitpid %i says %s",
|
log_unusual(sd->log, "Status closed, but waitpid %i says %s",
|
||||||
|
@ -458,6 +467,10 @@ static void destroy_subd(struct subd *sd)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fail_if_subd_fails && WIFSIGNALED(status))
|
||||||
|
fatal("Subdaemon %s killed with signal %i",
|
||||||
|
sd->name, WTERMSIG(status));
|
||||||
|
|
||||||
/* In case we're freed manually, such as peer_fail_permanent */
|
/* In case we're freed manually, such as peer_fail_permanent */
|
||||||
if (sd->conn)
|
if (sd->conn)
|
||||||
sd->conn = tal_free(sd->conn);
|
sd->conn = tal_free(sd->conn);
|
||||||
|
|
|
@ -101,6 +101,7 @@ class NodeFactory(object):
|
||||||
with open(os.path.join(lightning_dir, "dev_disconnect"), "w") as f:
|
with open(os.path.join(lightning_dir, "dev_disconnect"), "w") as f:
|
||||||
f.write("\n".join(disconnect))
|
f.write("\n".join(disconnect))
|
||||||
daemon.cmd_line.append("--dev-disconnect=dev_disconnect")
|
daemon.cmd_line.append("--dev-disconnect=dev_disconnect")
|
||||||
|
daemon.cmd_line.append("--dev-fail-on-subdaemon-fail")
|
||||||
rpc = LightningRpc(socket_path, self.executor)
|
rpc = LightningRpc(socket_path, self.executor)
|
||||||
|
|
||||||
node = utils.LightningNode(daemon, rpc, bitcoind, self.executor)
|
node = utils.LightningNode(daemon, rpc, bitcoind, self.executor)
|
||||||
|
|
Loading…
Add table
Reference in a new issue