From c9a907cd71a2e2c1a6738c6d0897caaad2f2557a Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 29 Jan 2019 11:11:55 +1030 Subject: [PATCH] common: handle peer input before gossipd input (for closingd, openingd) Similar to the previous "handle peer input before gossip input", this fixes similar potential deadlock for closingd and openingd which use peer_or_gossip_sync_read. Signed-off-by: Rusty Russell --- common/read_peer_msg.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/common/read_peer_msg.c b/common/read_peer_msg.c index 77b06abc0..3aac49909 100644 --- a/common/read_peer_msg.c +++ b/common/read_peer_msg.c @@ -26,18 +26,18 @@ u8 *peer_or_gossip_sync_read(const tal_t *ctx, select(peer_fd > gossip_fd ? peer_fd + 1 : gossip_fd + 1, &readfds, NULL, NULL, NULL); - if (FD_ISSET(gossip_fd, &readfds)) { - msg = wire_sync_read(ctx, gossip_fd); - if (!msg) - status_failed(STATUS_FAIL_GOSSIP_IO, - "Error reading gossip msg: %s", - strerror(errno)); - *from_gossipd = true; + if (FD_ISSET(peer_fd, &readfds)) { + msg = sync_crypto_read(ctx, cs, peer_fd); + *from_gossipd = false; return msg; } - msg = sync_crypto_read(ctx, cs, peer_fd); - *from_gossipd = false; + msg = wire_sync_read(ctx, gossip_fd); + if (!msg) + status_failed(STATUS_FAIL_GOSSIP_IO, + "Error reading gossip msg: %s", + strerror(errno)); + *from_gossipd = true; return msg; }