From 6e4d9acac3117f837a6304e0657a1017c543865f Mon Sep 17 00:00:00 2001 From: Simon Vrouwe Date: Sat, 26 Jan 2019 14:55:07 +0200 Subject: [PATCH] channeld: prioritize read from peer over (read from gossipd and) write to peer This solves (or at least reduces probability of) a deadlock in channeld when there is lot of gossip traffic, see issue #2286. That issue is almost identical to #1943 (deadlock in openingd) and so is the fix. --- channeld/channeld.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 18fe40482..69df8be3c 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -2928,6 +2928,10 @@ int main(int argc, char *argv[]) "Can't read command: %s", strerror(errno)); req_in(peer, msg); + } else if (FD_ISSET(PEER_FD, &rfds)) { + /* This could take forever, but who cares? */ + msg = sync_crypto_read(tmpctx, &peer->cs, PEER_FD); + peer_in(peer, msg); } else if (FD_ISSET(GOSSIP_FD, &rfds)) { msg = wire_sync_read(tmpctx, GOSSIP_FD); /* Gossipd hangs up on us to kill us when a new @@ -2935,10 +2939,6 @@ int main(int argc, char *argv[]) if (!msg) peer_failed_connection_lost(); handle_gossip_msg(PEER_FD, &peer->cs, take(msg)); - } else if (FD_ISSET(PEER_FD, &rfds)) { - /* This could take forever, but who cares? */ - msg = sync_crypto_read(tmpctx, &peer->cs, PEER_FD); - peer_in(peer, msg); } }