Skip to content

Commit

Permalink
Add further logs to message-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed Jan 1, 2024
1 parent 8bd2a0f commit fffe897
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions message-queue/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,13 @@ impl MessageQueue {
async fn send(socket: &mut TcpStream, msg: MessageQueueRequest) -> bool {
let msg = borsh::to_vec(&msg).unwrap();
let Ok(()) = socket.write_all(&u32::try_from(msg.len()).unwrap().to_le_bytes()).await else {
log::warn!("couldn't send the message len");
return false;
};
let Ok(()) = socket.write_all(&msg).await else {
log::warn!("couldn't write the message");
return false;
};
let Ok(()) = socket.write_all(&msg).await else { return false };
true
}

Expand Down Expand Up @@ -134,8 +138,12 @@ impl MessageQueue {
if !Self::send(&mut socket, msg.clone()).await {
continue 'outer;
}
let Ok(status) = socket.read_u8().await else {
continue 'outer;
let status = match socket.read_u8().await {
Ok(status) => status,
Err(e) => {
log::warn!("couldn't read status u8: {e:?}");
continue 'outer;
}
};
// If there wasn't a message, check again in 1s
// TODO: Use a notification system here
Expand All @@ -150,12 +158,17 @@ impl MessageQueue {
// Timeout after 5 seconds in case there's an issue with the length handling
let Ok(msg) = tokio::time::timeout(core::time::Duration::from_secs(5), async {
// Read the message length
let Ok(len) = socket.read_u32_le().await else {
return vec![];
let len = match socket.read_u32_le().await {
Ok(len) => len,
Err(e) => {
log::warn!("couldn't read len: {e:?}");
return vec![];
}
};
let mut buf = vec![0; usize::try_from(len).unwrap()];
// Read the message
let Ok(_) = socket.read_exact(&mut buf).await else {
log::warn!("couldn't read the message");
return vec![];
};
buf
Expand Down
2 changes: 2 additions & 0 deletions processor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ async fn run<N: Network, D: Db, Co: Coordinator>(mut raw_db: D, network: N, mut
loop {
let mut txn = raw_db.txn();

log::trace!("new db txn in run");

let mut outer_msg = None;

tokio::select! {
Expand Down

0 comments on commit fffe897

Please sign in to comment.