Skip to content

Commit 0388314

Browse files
SimonVrouwerustyrussell
authored andcommitted
JSON RPC: Calls made in shutdown loop receive error code -5: LIGHTNINGD_SHUTDOWN
1 parent 2096146 commit 0388314

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

common/jsonrpc_errors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ static const errcode_t PLUGIN_ERROR = -3;
2828
/* Plugin terminated while handling a request. */
2929
static const errcode_t PLUGIN_TERMINATED = -4;
3030

31+
/* Lightningd is shutting down while handling a request. */
32+
static const errcode_t LIGHTNINGD_SHUTDOWN = -5;
33+
3134
/* Errors from `pay`, `sendpay`, or `waitsendpay` commands */
3235
static const errcode_t PAY_IN_PROGRESS = 200;
3336
static const errcode_t PAY_RHASH_ALREADY_USED = 201;

lightningd/jsonrpc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,11 @@ parse_request(struct json_connection *jcon, const jsmntok_t tok[])
933933
json_tok_full(jcon->buffer, method));
934934
}
935935

936+
if (jcon->ld->state == LD_STATE_SHUTDOWN) {
937+
return command_fail(c, LIGHTNINGD_SHUTDOWN,
938+
"lightningd is shutting down");
939+
}
940+
936941
rpc_hook = tal(c, struct rpc_command_hook_payload);
937942
rpc_hook->cmd = c;
938943
/* Duplicate since we might outlive the connection */

lightningd/lightningd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,8 @@ int main(int argc, char *argv[])
11681168
* shut down.
11691169
*/
11701170
assert(io_loop_ret == ld);
1171+
1172+
/* Fail JSON RPC requests and ignore plugin's responses */
11711173
ld->state = LD_STATE_SHUTDOWN;
11721174

11731175
stop_fd = -1;

0 commit comments

Comments
 (0)