Skip to content

Commit d62abec

Browse files
committed
libplugin: call get_beglist async, in case they subscribe to the rpc_command hook.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Fixed: libplugin: plugins can now intercept `rpc_command` hook without deadlocking.
1 parent 0951526 commit d62abec

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

plugins/libplugin.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,27 @@ static const char **json_to_apilist(const tal_t *ctx, const char *buffer, const
14861486
return ret;
14871487
}
14881488

1489+
static struct command_result *get_beglist(struct command *aux_cmd,
1490+
const char *method,
1491+
const char *buf,
1492+
const jsmntok_t *result,
1493+
void *unused)
1494+
{
1495+
struct plugin *plugin = aux_cmd->plugin;
1496+
const char *err;
1497+
1498+
err = json_scan(tmpctx, buf, result,
1499+
"{configs:{i-promise-to-fix-broken-api-user?:%}}",
1500+
JSON_SCAN_TAL(plugin, json_to_apilist, &plugin->beglist));
1501+
if (err)
1502+
plugin_err(aux_cmd->plugin, "bad listconfigs '%.*s': %s",
1503+
json_tok_full_len(result),
1504+
json_tok_full(buf, result),
1505+
err);
1506+
1507+
return aux_command_done(aux_cmd);
1508+
}
1509+
14891510
static struct command_result *handle_init(struct command *cmd,
14901511
const char *buf,
14911512
const jsmntok_t *params)
@@ -1568,12 +1589,15 @@ static struct command_result *handle_init(struct command *cmd,
15681589
}
15691590

15701591
if (with_rpc) {
1571-
p->beglist = NULL;
1572-
rpc_scan(cmd, "listconfigs",
1573-
take(json_out_obj(NULL, "config", "i-promise-to-fix-broken-api-user")),
1574-
"{configs:{i-promise-to-fix-broken-api-user?:%}}",
1575-
JSON_SCAN_TAL(p, json_to_apilist, &p->beglist));
1592+
struct out_req *req;
1593+
struct command *aux_cmd = aux_command(cmd);
1594+
15761595
io_new_conn(p, p->rpc_conn->fd, rpc_conn_init, p);
1596+
/* In case they intercept rpc_command, we can't do this sync. */
1597+
req = jsonrpc_request_start(aux_cmd, "listconfigs",
1598+
get_beglist, plugin_broken_cb, NULL);
1599+
json_add_string(req->js, "config", "i-promise-to-fix-broken-api-user");
1600+
send_outreq(req);
15771601
}
15781602

15791603
return command_success(cmd, json_out_obj(cmd, NULL, NULL));
@@ -2343,6 +2367,7 @@ static struct plugin *new_plugin(const tal_t *ctx,
23432367
p->rpc_toks = toks_alloc(p);
23442368
p->next_outreq_id = 0;
23452369
strmap_init(&p->out_reqs);
2370+
p->beglist = NULL;
23462371

23472372
p->desired_features = tal_steal(p, features);
23482373
if (init_rpc) {

0 commit comments

Comments
 (0)