Skip to content

Commit a0fd72e

Browse files
committed
connectd: warn if we ignore peer incoming for longer than 5 seconds.
One reason why ping processing could be slow is that, once we receive a message from the peer to send to a subdaemon, we don't listen for others until we've drained that subdaemon queue entirely. This can happens for reestablish: slow machines can take a while to set that subdaemon up. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 0938d54 commit a0fd72e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

connectd/connectd.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static struct peer *new_peer(struct daemon *daemon,
147147
peer->sent_to_peer = NULL;
148148
peer->urgent = false;
149149
peer->draining = false;
150+
peer->peer_in_lastmsg = -1;
150151
peer->peer_outq = msg_queue_new(peer, false);
151152
peer->last_recv_time = time_now();
152153
peer->is_websocket = is_websocket;

connectd/connectd.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ struct peer {
9696
/* Last time we received traffic */
9797
struct timeabs last_recv_time;
9898

99+
/* How long have we been ignoring peer input? */
100+
struct timemono peer_in_lasttime;
101+
int peer_in_lastmsg;
102+
99103
/* Ratelimits for onion messages. One token per msec. */
100104
size_t onionmsg_incoming_tokens;
101105
struct timemono onionmsg_last_incoming;

connectd/multiplex.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,16 @@ static struct io_plan *write_to_subd(struct io_conn *subd_conn,
11471147

11481148
/* Tell them to read again. */
11491149
io_wake(&subd->peer->peer_in);
1150+
if (subd->peer->peer_in_lastmsg != -1) {
1151+
u64 msec = time_to_msec(timemono_between(time_mono(),
1152+
subd->peer->peer_in_lasttime));
1153+
if (msec > 5000)
1154+
status_peer_broken(&subd->peer->id,
1155+
"wake delay for %s: %"PRIu64"msec",
1156+
peer_wire_name(subd->peer->peer_in_lastmsg),
1157+
msec);
1158+
subd->peer->peer_in_lastmsg = -1;
1159+
}
11501160

11511161
/* Wait for them to wake us */
11521162
return msg_queue_wait(subd_conn, subd->outq,
@@ -1317,6 +1327,9 @@ static struct io_plan *read_body_from_peer_done(struct io_conn *peer_conn,
13171327
}
13181328

13191329
/* Wait for them to wake us */
1330+
peer->peer_in_lastmsg = type;
1331+
peer->peer_in_lasttime = time_mono();
1332+
13201333
return io_wait(peer_conn, &peer->peer_in, next_read, peer);
13211334
}
13221335

0 commit comments

Comments
 (0)