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.
This commit is contained in:
Simon Vrouwe 2019-01-26 14:55:07 +02:00 committed by Christian Decker
parent 10057c8335
commit 6e4d9acac3

View file

@ -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);
}
}