Browse Source

lightningd: fix similar race in `stop`.

Tested by putting a sleep in the rpc_command hook.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-prep
Rusty Russell 4 years ago
committed by neil saitug
parent
commit
d5d9858b7b
  1. 11
      lightningd/jsonrpc.c
  2. 7
      lightningd/lightningd.c

11
lightningd/jsonrpc.c

@ -192,10 +192,17 @@ static struct command_result *json_stop(struct command *cmd,
if (!param(cmd, buffer, params, NULL))
return command_param_failed();
/* This can't have closed yet! */
cmd->ld->stop_conn = cmd->jcon->conn;
log_unusual(cmd->ld->log, "JSON-RPC shutdown");
/* With rpc_command_hook, jcon might have closed in the meantime! */
if (!cmd->jcon) {
/* Return us to toplevel lightningd.c */
io_break(cmd->ld);
return command_still_pending(cmd);
}
cmd->ld->stop_conn = cmd->jcon->conn;
/* This is the one place where result is a literal string. */
jout = json_out_new(tmpctx);
json_out_start(jout, NULL, '{');

7
lightningd/lightningd.c

@ -1021,12 +1021,13 @@ int main(int argc, char *argv[])
assert(io_loop_ret == ld);
ld->state = LD_STATE_SHUTDOWN;
stop_fd = -1;
stop_response = NULL;
/* Were we exited via `lightningd_exit`? */
if (ld->exit_code) {
exit_code = *ld->exit_code;
stop_fd = -1;
stop_response = NULL;
} else {
} else if (ld->stop_conn) {
/* Keep this fd around, to write final response at the end. */
stop_fd = io_conn_fd(ld->stop_conn);
io_close_taken_fd(ld->stop_conn);

Loading…
Cancel
Save