Skip to content

Commit eae0904

Browse files
committed
fix: Fix reentrancy bug in read_event()
Per the external documentation, there is an invariant that read_event() will not call back into the SocketDescriptor, but the actual code flushed the outbound queue. Fix the bug and use the type system to guarantee this behavior in the future. By changing the function parameters to use `impl PayloadQueuer` the function will only have access to functions on that interface throughout the execution, but still be able to pass the OutboundQueue object since it satisfies the trait bounds. Functions such as enqueue_message() also take a `impl PayloadQueuer` so they can be called from that context, but functions that need the SocketDescriptorFlusher interface will fail at compile-time and point to the issue before any tests need to be run. This also fixes up tests and the tokio implementation that did not implement the proper behavior and relied on read_event() calling send_data().
1 parent eadc443 commit eae0904

File tree

3 files changed

+165
-84
lines changed

3 files changed

+165
-84
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl Connection {
180180
Ok(len) => {
181181
prepare_read_write_call!();
182182
let read_res = peer_manager.read_event(&mut our_descriptor, &buf[0..len]);
183+
peer_manager.process_events();
183184
let mut us_lock = us.lock().unwrap();
184185
match read_res {
185186
Ok(pause_read) => {

0 commit comments

Comments
 (0)