From 644daa02e30b1b4c279f46b93040a1e1a0ba54dd Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Fri, 14 Feb 2020 18:08:59 +0100 Subject: [PATCH] plugin: Cleanup a plugin as soon as its stdout closes We were waiting for both stdin and stdout to close, however that resulted in us deferring cleanup indefinitely since we did not poll stdout for being writable most of the time. On the other hand we are almost always polling the plugin's stdout, so that notifies us as soon as the plugin stops. Changelog-Fixed: plugin: Plugins no longer linger indefinitely if their process terminates --- lightningd/plugin.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lightningd/plugin.c b/lightningd/plugin.c index fbfd6caad..2db21cc9e 100644 --- a/lightningd/plugin.c +++ b/lightningd/plugin.c @@ -439,14 +439,8 @@ static struct io_plan *plugin_write_json(struct io_conn *conn, */ static void plugin_conn_finish(struct io_conn *conn, struct plugin *plugin) { - if (conn == plugin->stdin_conn) - plugin->stdin_conn = NULL; - - else if (conn == plugin->stdout_conn) - plugin->stdout_conn = NULL; - - if (plugin->stdin_conn == NULL && plugin->stdout_conn == NULL) - tal_free(plugin); + plugin->stdout_conn = NULL; + tal_free(plugin); } struct io_plan *plugin_stdin_conn_init(struct io_conn *conn, @@ -454,8 +448,8 @@ struct io_plan *plugin_stdin_conn_init(struct io_conn *conn, { /* We write to their stdin */ /* We don't have anything queued yet, wait for notification */ + plugin->stdin_conn = tal_steal(plugin, conn); plugin->stdin_conn = conn; - io_set_finish(conn, plugin_conn_finish, plugin); return io_wait(plugin->stdin_conn, plugin, plugin_write_json, plugin); }