lightningd: don't process request twice if plugin dies.

We remove it from the pending_requests strmap before calling it,
so it doesn't get called again by destroy_plugin.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2023-10-24 12:11:30 +10:30
parent 7c1d07a94f
commit 6f1bb6fa41
2 changed files with 9 additions and 7 deletions

View file

@ -629,6 +629,12 @@ static bool was_plugin_destroyed(struct plugin_destroyed *pd)
return true; return true;
} }
static void destroy_request(struct jsonrpc_request *req,
struct plugin *plugin)
{
strmap_del(&plugin->pending_requests, req->id, NULL);
}
static void plugin_response_handle(struct plugin *plugin, static void plugin_response_handle(struct plugin *plugin,
const jsmntok_t *toks, const jsmntok_t *toks,
const jsmntok_t *idtok) const jsmntok_t *idtok)
@ -648,6 +654,9 @@ static void plugin_response_handle(struct plugin *plugin,
/* Request callback often frees request: if not, we do. */ /* Request callback often frees request: if not, we do. */
ctx = tal(NULL, char); ctx = tal(NULL, char);
tal_steal(ctx, request); tal_steal(ctx, request);
/* Don't keep track of this request; we will terminate it */
tal_del_destructor2(request, destroy_request, plugin);
destroy_request(request, plugin);
request->response_cb(plugin->buffer, toks, idtok, request->response_cb_arg); request->response_cb(plugin->buffer, toks, idtok, request->response_cb_arg);
tal_free(ctx); tal_free(ctx);
} }
@ -2356,12 +2365,6 @@ void plugins_notify(struct plugins *plugins,
} }
} }
static void destroy_request(struct jsonrpc_request *req,
struct plugin *plugin)
{
strmap_del(&plugin->pending_requests, req->id, NULL);
}
void plugin_request_send(struct plugin *plugin, void plugin_request_send(struct plugin *plugin,
struct jsonrpc_request *req) struct jsonrpc_request *req)
{ {

View file

@ -1478,7 +1478,6 @@ def test_sendpay_notifications_nowaiter(node_factory):
assert len(results['sendpay_failure']) == 1 assert len(results['sendpay_failure']) == 1
@pytest.mark.xfail(strict=True)
def test_rpc_command_hook(node_factory): def test_rpc_command_hook(node_factory):
"""Test the `rpc_command` hook chain""" """Test the `rpc_command` hook chain"""
plugin = [ plugin = [