@@ -31,7 +31,7 @@ use libafl_bolts::{shmem::StdShMemProvider, staterestore::StateRestorer};
31
31
use serde:: { de:: DeserializeOwned , Deserialize , Serialize } ;
32
32
use tokio:: {
33
33
io:: { AsyncReadExt , AsyncWriteExt } ,
34
- sync:: { broadcast, mpsc} ,
34
+ sync:: { broadcast, broadcast :: error :: RecvError , mpsc} ,
35
35
task:: { spawn, JoinHandle } ,
36
36
} ;
37
37
#[ cfg( feature = "std" ) ]
@@ -111,8 +111,8 @@ where
111
111
#[ tokio:: main( flavor = "current_thread" ) ]
112
112
#[ allow( clippy:: too_many_lines) ]
113
113
pub async fn broker_loop ( & mut self ) -> Result < ( ) , Error > {
114
- let ( tx_bc, rx) = broadcast:: channel ( 1024 ) ;
115
- let ( tx, mut rx_mpsc) = mpsc:: channel ( 1024 ) ;
114
+ let ( tx_bc, rx) = broadcast:: channel ( 65536 ) ;
115
+ let ( tx, mut rx_mpsc) = mpsc:: channel ( 65536 ) ;
116
116
117
117
let exit_cleanly_after = self . exit_cleanly_after ;
118
118
@@ -224,13 +224,14 @@ where
224
224
spawn ( async move {
225
225
// In a loop, read data from the socket and write the data back.
226
226
loop {
227
- let buf: Vec < u8 > = rx_inner
228
- . lock ( )
229
- . await
230
- . recv ( )
231
- . await
232
- . expect ( "Could not receive" ) ;
233
- // TODO handle full capacity, Lagged https://docs.rs/tokio/latest/tokio/sync/broadcast/error/enum.RecvError.html
227
+ let buf: Vec < u8 > = match rx_inner. lock ( ) . await . recv ( ) . await {
228
+ Ok ( buf) => buf,
229
+ Err ( RecvError :: Lagged ( num) ) => {
230
+ log:: error!( "Receiver lagged, skipping {num} messages" ) ;
231
+ continue ;
232
+ }
233
+ _ => panic ! ( "Could not receive" ) ,
234
+ } ;
234
235
235
236
#[ cfg( feature = "tcp_debug" ) ]
236
237
println ! ( "{buf:?}" ) ;
@@ -704,7 +705,7 @@ where
704
705
if self_id == other_client_id {
705
706
panic ! ( "Own ID should never have been sent by the broker" ) ;
706
707
} else {
707
- println ! ( "{self_id:?} (from {other_client_id:?}) Received: {buf:?}" ) ;
708
+ log :: info !( "{self_id:?} (from {other_client_id:?}) Received: {buf:?}" ) ;
708
709
709
710
let event = postcard:: from_bytes ( & buf[ 4 ..] ) ?;
710
711
self . handle_in_client ( fuzzer, executor, state, other_client_id, event) ?;
0 commit comments