Skip to content

Commit a6463ec

Browse files
committed
Fix bogus reentrancy from read_event -> do_attempt_write_data
`Julian Knutsen <[email protected]>` pointed out in a previous discussion that `read_event` can reenter user code despite the documentation stating explicitly that it will not. This was addressed in lightningdevkit#456 by simply codifying the reentrancy, but its somewhat simpler to just drop the `do_attempt_write_data` call. Ideally we could land most of Julian's work, but its still in need of substantial git history cleanup to get it in a reviewable state and this solves the immediate issue.
1 parent f4323d9 commit a6463ec

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
807807
}
808808
}
809809

810-
self.do_attempt_write_data(peer_descriptor, peer);
811-
812810
peer.pending_outbound_buffer.len() > 10 // pause_read
813811
}
814812
};
@@ -1467,7 +1465,9 @@ mod tests {
14671465
let initial_data = peer_b.new_outbound_connection(a_id, fd_b.clone()).unwrap();
14681466
peer_a.new_inbound_connection(fd_a.clone()).unwrap();
14691467
assert_eq!(peer_a.read_event(&mut fd_a, &initial_data).unwrap(), false);
1468+
peer_a.process_events();
14701469
assert_eq!(peer_b.read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap(), false);
1470+
peer_b.process_events();
14711471
assert_eq!(peer_a.read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap(), false);
14721472
(fd_a.clone(), fd_b.clone())
14731473
}
@@ -1506,10 +1506,12 @@ mod tests {
15061506

15071507
// peers[0] awaiting_pong is set to true, but the Peer is still connected
15081508
peers[0].timer_tick_occurred();
1509+
peers[0].process_events();
15091510
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 1);
15101511

15111512
// Since timer_tick_occurred() is called again when awaiting_pong is true, all Peers are disconnected
15121513
peers[0].timer_tick_occurred();
1514+
peers[0].process_events();
15131515
assert_eq!(peers[0].peers.lock().unwrap().peers.len(), 0);
15141516
}
15151517

@@ -1530,7 +1532,9 @@ mod tests {
15301532
let (mut fd_a, mut fd_b) = establish_connection(&peers[0], &peers[1]);
15311533

15321534
// Make each peer to read the messages that the other peer just wrote to them.
1535+
peers[0].process_events();
15331536
peers[1].read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap();
1537+
peers[1].process_events();
15341538
peers[0].read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap();
15351539

15361540
// Check that each peer has received the expected number of channel updates and channel

0 commit comments

Comments
 (0)