Skip to content

Commit d64e1b9

Browse files
committed
Make fuzz_threaded_connections more robust
In `fuzz_threaded_connections`, if one thread is being run while another is starved, and the running thread manages to call `timer_tick_ocurred` twice after the starved thread constructs the inbound connection but before it delivers the first bytes, we'll receive an immediate error and `unwrap` it, causing failure. The fix is trivial, simply remove the unwrap and return if we're already disconnected when we do the initial read. While we're here, we also reduce the frequency of the `timer_tick_ocurred` calls to give us a chance to occasionally deliver some additional messages. Fixes #2073
1 parent af76fac commit d64e1b9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ mod tests {
23342334
let addr_b = NetAddress::IPv4{addr: [127, 0, 0, 1], port: 1001};
23352335
let initial_data = peers[1].new_outbound_connection(id_a, fd_b.clone(), Some(addr_a.clone())).unwrap();
23362336
peers[0].new_inbound_connection(fd_a.clone(), Some(addr_b.clone())).unwrap();
2337-
assert_eq!(peers[0].read_event(&mut fd_a, &initial_data).unwrap(), false);
2337+
if peers[0].read_event(&mut fd_a, &initial_data).is_err() { break; }
23382338

23392339
while start_time.elapsed() < std::time::Duration::from_secs(1) {
23402340
peers[0].process_events();
@@ -2364,8 +2364,10 @@ mod tests {
23642364
},
23652365
});
23662366

2367-
peers[0].timer_tick_occurred();
2368-
peers[1].timer_tick_occurred();
2367+
if ctr % 2 == 0 {
2368+
peers[0].timer_tick_occurred();
2369+
peers[1].timer_tick_occurred();
2370+
}
23692371
}
23702372

23712373
peers[0].socket_disconnected(&fd_a);

0 commit comments

Comments
 (0)