JSON RPC: Calls made in shutdown loop receive error code -5: LIGHTNINGD_SHUTDOWN

This commit is contained in:
Simon Vrouwe
2021-11-10 11:08:49 +02:00
committed by Rusty Russell
parent 209614677a
commit 0388314ef8
3 changed files with 10 additions and 0 deletions

View File

@@ -28,6 +28,9 @@ static const errcode_t PLUGIN_ERROR = -3;
/* Plugin terminated while handling a request. */ /* Plugin terminated while handling a request. */
static const errcode_t PLUGIN_TERMINATED = -4; static const errcode_t PLUGIN_TERMINATED = -4;
/* Lightningd is shutting down while handling a request. */
static const errcode_t LIGHTNINGD_SHUTDOWN = -5;
/* Errors from `pay`, `sendpay`, or `waitsendpay` commands */ /* Errors from `pay`, `sendpay`, or `waitsendpay` commands */
static const errcode_t PAY_IN_PROGRESS = 200; static const errcode_t PAY_IN_PROGRESS = 200;
static const errcode_t PAY_RHASH_ALREADY_USED = 201; static const errcode_t PAY_RHASH_ALREADY_USED = 201;

View File

@@ -933,6 +933,11 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
json_tok_full(jcon->buffer, method)); json_tok_full(jcon->buffer, method));
} }
if (jcon->ld->state == LD_STATE_SHUTDOWN) {
return command_fail(c, LIGHTNINGD_SHUTDOWN,
"lightningd is shutting down");
}
rpc_hook = tal(c, struct rpc_command_hook_payload); rpc_hook = tal(c, struct rpc_command_hook_payload);
rpc_hook->cmd = c; rpc_hook->cmd = c;
/* Duplicate since we might outlive the connection */ /* Duplicate since we might outlive the connection */

View File

@@ -1168,6 +1168,8 @@ int main(int argc, char *argv[])
* shut down. * shut down.
*/ */
assert(io_loop_ret == ld); assert(io_loop_ret == ld);
/* Fail JSON RPC requests and ignore plugin's responses */
ld->state = LD_STATE_SHUTDOWN; ld->state = LD_STATE_SHUTDOWN;
stop_fd = -1; stop_fd = -1;