Skip to content

Commit cec627d

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 59c1078 commit cec627d

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
@@ -808,8 +808,6 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
808808
}
809809
}
810810

811-
self.do_attempt_write_data(peer_descriptor, peer);
812-
813811
peer.pending_outbound_buffer.len() > 10 // pause_read
814812
}
815813
};
@@ -1468,7 +1466,9 @@ mod tests {
14681466
let initial_data = peer_b.new_outbound_connection(a_id, fd_b.clone()).unwrap();
14691467
peer_a.new_inbound_connection(fd_a.clone()).unwrap();
14701468
assert_eq!(peer_a.read_event(&mut fd_a, &initial_data).unwrap(), false);
1469+
peer_a.process_events();
14711470
assert_eq!(peer_b.read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap(), false);
1471+
peer_b.process_events();
14721472
assert_eq!(peer_a.read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap(), false);
14731473
(fd_a.clone(), fd_b.clone())
14741474
}
@@ -1507,10 +1507,12 @@ mod tests {
15071507

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

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

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

15331535
// Make each peer to read the messages that the other peer just wrote to them.
1536+
peers[0].process_events();
15341537
peers[1].read_event(&mut fd_b, &fd_a.outbound_data.lock().unwrap().split_off(0)).unwrap();
1538+
peers[1].process_events();
15351539
peers[0].read_event(&mut fd_a, &fd_b.outbound_data.lock().unwrap().split_off(0)).unwrap();
15361540

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

0 commit comments

Comments
 (0)