diff --git a/lightningd/subd.c b/lightningd/subd.c index c0467d4c11f3..0a9b0c2beb53 100644 --- a/lightningd/subd.c +++ b/lightningd/subd.c @@ -419,6 +419,11 @@ static bool handle_version(struct subd *sd, const u8 *msg) io_break(sd->ld); return false; } + + sd->rcvd_version = true; + /* In case there are outgoing msgs, we can send now. */ + msg_wake(sd->outq); + return true; } @@ -605,10 +610,15 @@ static void destroy_subd(struct subd *sd) static struct io_plan *msg_send_next(struct io_conn *conn, struct subd *sd) { - const u8 *msg = msg_dequeue(sd->outq); + const u8 *msg; int fd; + /* Don't send if we haven't read version! */ + if (!sd->rcvd_version) + return msg_queue_wait(conn, sd->outq, msg_send_next, sd); + /* Nothing to do? Wait for msg_enqueue. */ + msg = msg_dequeue(sd->outq); if (!msg) return msg_queue_wait(conn, sd->outq, msg_send_next, sd); @@ -702,6 +712,7 @@ static struct subd *new_subd(struct lightningd *ld, tal_add_destructor(sd, destroy_subd); list_head_init(&sd->reqs); sd->channel = channel; + sd->rcvd_version = false; if (node_id) sd->node_id = tal_dup(sd, struct node_id, node_id); else diff --git a/lightningd/subd.h b/lightningd/subd.h index 7fc584cad63d..94fabf9e3a32 100644 --- a/lightningd/subd.h +++ b/lightningd/subd.h @@ -32,6 +32,9 @@ struct subd { /* If we are associated with a single channel, this points to it. */ void *channel; + /* Have we received the version msg yet? Don't send until we do. */ + bool rcvd_version; + /* For logging */ struct log *log; const struct node_id *node_id;