mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 06:41:44 +01:00
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>
This commit is contained in:
parent
5e6b0f9445
commit
d5d9858b7b
2 changed files with 13 additions and 5 deletions
|
@ -192,10 +192,17 @@ static struct command_result *json_stop(struct command *cmd,
|
||||||
if (!param(cmd, buffer, params, NULL))
|
if (!param(cmd, buffer, params, NULL))
|
||||||
return command_param_failed();
|
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");
|
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. */
|
/* This is the one place where result is a literal string. */
|
||||||
jout = json_out_new(tmpctx);
|
jout = json_out_new(tmpctx);
|
||||||
json_out_start(jout, NULL, '{');
|
json_out_start(jout, NULL, '{');
|
||||||
|
|
|
@ -1021,12 +1021,13 @@ int main(int argc, char *argv[])
|
||||||
assert(io_loop_ret == ld);
|
assert(io_loop_ret == ld);
|
||||||
ld->state = LD_STATE_SHUTDOWN;
|
ld->state = LD_STATE_SHUTDOWN;
|
||||||
|
|
||||||
|
stop_fd = -1;
|
||||||
|
stop_response = NULL;
|
||||||
|
|
||||||
/* Were we exited via `lightningd_exit`? */
|
/* Were we exited via `lightningd_exit`? */
|
||||||
if (ld->exit_code) {
|
if (ld->exit_code) {
|
||||||
exit_code = *ld->exit_code;
|
exit_code = *ld->exit_code;
|
||||||
stop_fd = -1;
|
} else if (ld->stop_conn) {
|
||||||
stop_response = NULL;
|
|
||||||
} else {
|
|
||||||
/* Keep this fd around, to write final response at the end. */
|
/* Keep this fd around, to write final response at the end. */
|
||||||
stop_fd = io_conn_fd(ld->stop_conn);
|
stop_fd = io_conn_fd(ld->stop_conn);
|
||||||
io_close_taken_fd(ld->stop_conn);
|
io_close_taken_fd(ld->stop_conn);
|
||||||
|
|
Loading…
Add table
Reference in a new issue