mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
improve tracing and spans in network crate
This commit is contained in:
parent
fc10c16fa1
commit
b59fc2ff0c
@ -25,6 +25,7 @@ use std::{
|
|||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
use tracing::*;
|
use tracing::*;
|
||||||
|
use tracing_futures::Instrument;
|
||||||
|
|
||||||
pub(crate) type A2bStreamOpen = (Prio, Promises, oneshot::Sender<Stream>);
|
pub(crate) type A2bStreamOpen = (Prio, Promises, oneshot::Sender<Stream>);
|
||||||
pub(crate) type S2bCreateChannel = (Cid, Sid, Protocols, Vec<(Cid, Frame)>, oneshot::Sender<()>);
|
pub(crate) type S2bCreateChannel = (Cid, Sid, Protocols, Vec<(Cid, Frame)>, oneshot::Sender<()>);
|
||||||
@ -477,6 +478,7 @@ impl BParticipant {
|
|||||||
trace!(?cid, "Running channel in participant");
|
trace!(?cid, "Running channel in participant");
|
||||||
channel
|
channel
|
||||||
.run(protocol, w2b_frames_s, leftover_cid_frame)
|
.run(protocol, w2b_frames_s, leftover_cid_frame)
|
||||||
|
.instrument(tracing::info_span!("", ?cid))
|
||||||
.await;
|
.await;
|
||||||
#[cfg(feature = "metrics")]
|
#[cfg(feature = "metrics")]
|
||||||
self.metrics
|
self.metrics
|
||||||
|
@ -80,11 +80,10 @@ impl TcpProtocol {
|
|||||||
} {
|
} {
|
||||||
Some(Ok(_)) => false,
|
Some(Ok(_)) => false,
|
||||||
Some(Err(e)) => {
|
Some(Err(e)) => {
|
||||||
debug!(
|
info!(
|
||||||
?cid,
|
|
||||||
?e,
|
?e,
|
||||||
"Closing tcp protocol due to read error, sending close frame to gracefully \
|
"Closing tcp protocol due to read error, pushing close frame (to own \
|
||||||
shutdown"
|
Channel/Participant) to gracefully shutdown"
|
||||||
);
|
);
|
||||||
w2c_cid_frame_s
|
w2c_cid_frame_s
|
||||||
.send((cid, Frame::Shutdown))
|
.send((cid, Frame::Shutdown))
|
||||||
@ -93,7 +92,7 @@ impl TcpProtocol {
|
|||||||
true
|
true
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
trace!(?cid, "shutdown requested");
|
trace!("shutdown requested");
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -119,7 +118,7 @@ impl TcpProtocol {
|
|||||||
macro_rules! read_or_close {
|
macro_rules! read_or_close {
|
||||||
($x:expr) => {
|
($x:expr) => {
|
||||||
if TcpProtocol::read_or_close(cid, &stream, $x, w2c_cid_frame_s, &mut end_r).await {
|
if TcpProtocol::read_or_close(cid, &stream, $x, w2c_cid_frame_s, &mut end_r).await {
|
||||||
info!("Tcp stream closed, shutting down read");
|
trace!("read_or_close requested a shutdown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -228,7 +227,7 @@ impl TcpProtocol {
|
|||||||
) -> bool {
|
) -> bool {
|
||||||
match stream.write_all(&bytes).await {
|
match stream.write_all(&bytes).await {
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!(
|
info!(
|
||||||
?e,
|
?e,
|
||||||
"Got an error writing to tcp, going to close this channel"
|
"Got an error writing to tcp, going to close this channel"
|
||||||
);
|
);
|
||||||
@ -255,7 +254,7 @@ impl TcpProtocol {
|
|||||||
macro_rules! write_or_close {
|
macro_rules! write_or_close {
|
||||||
($x:expr) => {
|
($x:expr) => {
|
||||||
if TcpProtocol::write_or_close(&mut stream, $x, &mut c2w_frame_r).await {
|
if TcpProtocol::write_or_close(&mut stream, $x, &mut c2w_frame_r).await {
|
||||||
info!("Tcp stream closed, shutting down write");
|
trace!("write_or_close requested a shutdown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -512,7 +512,11 @@ impl Scheduler {
|
|||||||
metrics.clone(),
|
metrics.clone(),
|
||||||
send_handshake,
|
send_handshake,
|
||||||
);
|
);
|
||||||
match handshake.setup(&protocol).await {
|
match handshake
|
||||||
|
.setup(&protocol)
|
||||||
|
.instrument(tracing::info_span!("handshake", ?cid))
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok((pid, sid, secret, leftover_cid_frame)) => {
|
Ok((pid, sid, secret, leftover_cid_frame)) => {
|
||||||
trace!(
|
trace!(
|
||||||
?cid,
|
?cid,
|
||||||
@ -583,14 +587,18 @@ impl Scheduler {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let pi = &participants[&pid];
|
let pi = &participants[&pid];
|
||||||
trace!("2nd+ channel of participant, going to compare security ids");
|
trace!(
|
||||||
|
?cid,
|
||||||
|
"2nd+ channel of participant, going to compare security ids"
|
||||||
|
);
|
||||||
if pi.secret != secret {
|
if pi.secret != secret {
|
||||||
warn!(
|
warn!(
|
||||||
|
?cid,
|
||||||
?pid,
|
?pid,
|
||||||
?secret,
|
?secret,
|
||||||
"Detected incompatible Secret!, this is probably an attack!"
|
"Detected incompatible Secret!, this is probably an attack!"
|
||||||
);
|
);
|
||||||
error!("Just dropping here, TODO handle this correctly!");
|
error!(?cid, "Just dropping here, TODO handle this correctly!");
|
||||||
//TODO
|
//TODO
|
||||||
if let Some(pid_oneshot) = s2a_return_pid_s {
|
if let Some(pid_oneshot) = s2a_return_pid_s {
|
||||||
// someone is waiting with `connect`, so give them their Error
|
// someone is waiting with `connect`, so give them their Error
|
||||||
@ -604,6 +612,7 @@ impl Scheduler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error!(
|
error!(
|
||||||
|
?cid,
|
||||||
"Ufff i cant answer the pid_oneshot. as i need to create the SAME \
|
"Ufff i cant answer the pid_oneshot. as i need to create the SAME \
|
||||||
participant. maybe switch to ARC"
|
participant. maybe switch to ARC"
|
||||||
);
|
);
|
||||||
@ -614,7 +623,7 @@ impl Scheduler {
|
|||||||
Err(()) => {
|
Err(()) => {
|
||||||
if let Some(pid_oneshot) = s2a_return_pid_s {
|
if let Some(pid_oneshot) = s2a_return_pid_s {
|
||||||
// someone is waiting with `connect`, so give them their Error
|
// someone is waiting with `connect`, so give them their Error
|
||||||
trace!("returning the Err to api who requested the connect");
|
trace!(?cid, "returning the Err to api who requested the connect");
|
||||||
pid_oneshot
|
pid_oneshot
|
||||||
.send(Err(std::io::Error::new(
|
.send(Err(std::io::Error::new(
|
||||||
std::io::ErrorKind::PermissionDenied,
|
std::io::ErrorKind::PermissionDenied,
|
||||||
@ -625,7 +634,7 @@ impl Scheduler {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.instrument(tracing::trace_span!("")),
|
.instrument(tracing::info_span!("")),
|
||||||
); /*WORKAROUND FOR SPAN NOT TO GET LOST*/
|
); /*WORKAROUND FOR SPAN NOT TO GET LOST*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,15 +94,16 @@ pub fn handle_client_disconnect(server: &mut Server, entity: EcsEntity) -> Event
|
|||||||
if let Err(e) = block_on(participant.disconnect()) {
|
if let Err(e) = block_on(participant.disconnect()) {
|
||||||
debug!(
|
debug!(
|
||||||
?e,
|
?e,
|
||||||
|
?pid,
|
||||||
"Error when disconnecting client, maybe the pipe already broke"
|
"Error when disconnecting client, maybe the pipe already broke"
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
trace!(?pid, "finished disconnect");
|
trace!(?pid, "finished disconnect");
|
||||||
let elapsed = now.elapsed();
|
let elapsed = now.elapsed();
|
||||||
if elapsed.as_millis() > 100 {
|
if elapsed.as_millis() > 100 {
|
||||||
warn!(?elapsed, "disconecting took quite long");
|
warn!(?elapsed, ?pid, "disconecting took quite long");
|
||||||
} else {
|
} else {
|
||||||
debug!(?elapsed, "disconecting took");
|
debug!(?elapsed, ?pid, "disconecting took");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user