Skip to content

Commit 40d111b

Browse files
committed
connectd: don't immediately stop reading from peer once we read a message.
If we do this, we can cause delays in non-channel messages (like gossip, and pings). On a busy system, a WIRE_REESTABLISH message can easily take a second to resolve, as a new subdaemon has to be spun up and connected before we can drain the queue). It also should be slightly more efficient in processing common packet patterns (ADD then COMMITMENT_SIGNED, etc). Signed-off-by: Rusty Russell <[email protected]> Changelog-Fixed: We will now process incoming non-channel messages (gossip, pings) in a more timely manner.
1 parent 6c4b7f6 commit 40d111b

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

connectd/multiplex.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,11 +1252,20 @@ static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
12521252
close_subd_timeout, subd));
12531253
}
12541254

1255-
/* Wait for them to wake us */
1256-
peer->peer_in_lastmsg = type;
1257-
peer->peer_in_lasttime = time_mono();
1255+
/* We used to io_wait after every message, but that means we don't read
1256+
* *non-channel* messages (gossip, pings) either. So as a compromise,
1257+
* we allow a handful of messages to be queued before we ignore the
1258+
* peer until we've drained the outgoing queue. */
1259+
if (msg_queue_length(subd->outq) > 5) {
1260+
/* Wait for them to wake us (oldest packet) */
1261+
if (peer->peer_in_lastmsg == -1) {
1262+
peer->peer_in_lastmsg = type;
1263+
peer->peer_in_lasttime = time_mono();
1264+
}
12581265

1259-
return io_wait(peer_conn, &peer->peer_in, next_read, peer);
1266+
return io_wait(peer_conn, &peer->peer_in, next_read, peer);
1267+
}
1268+
return next_read(peer_conn, peer);
12601269
}
12611270

12621271
static struct io_plan *read_body_from_peer(struct io_conn *peer_conn,

0 commit comments

Comments
 (0)