mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
drop msg if sync_sender buffer is full (do not close peer connection) (#3164)
This commit is contained in:
parent
5c7bc3d8cd
commit
bde19777f0
2 changed files with 19 additions and 11 deletions
|
@ -38,6 +38,8 @@ use std::{
|
||||||
thread::{self, JoinHandle},
|
thread::{self, JoinHandle},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub const SEND_CHANNEL_CAP: usize = 100;
|
||||||
|
|
||||||
const HEADER_IO_TIMEOUT: Duration = Duration::from_millis(2000);
|
const HEADER_IO_TIMEOUT: Duration = Duration::from_millis(2000);
|
||||||
const CHANNEL_TIMEOUT: Duration = Duration::from_millis(1000);
|
const CHANNEL_TIMEOUT: Duration = Duration::from_millis(1000);
|
||||||
const BODY_IO_TIMEOUT: Duration = Duration::from_millis(60000);
|
const BODY_IO_TIMEOUT: Duration = Duration::from_millis(60000);
|
||||||
|
@ -130,8 +132,6 @@ impl<'a> Message<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SEND_CHANNEL_CAP: usize = 100;
|
|
||||||
|
|
||||||
pub struct StopHandle {
|
pub struct StopHandle {
|
||||||
/// Channel to close the connection
|
/// Channel to close the connection
|
||||||
stopped: Arc<AtomicBool>,
|
stopped: Arc<AtomicBool>,
|
||||||
|
@ -178,9 +178,24 @@ pub struct ConnHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnHandle {
|
impl ConnHandle {
|
||||||
|
/// Send msg via the synchronous, bounded channel (sync_sender).
|
||||||
|
/// Two possible failure cases -
|
||||||
|
/// * Disconnected: Propagate this up to the caller so the peer connection can be closed.
|
||||||
|
/// * Full: Our internal msg buffer is full. This is not a problem with the peer connection
|
||||||
|
/// and we do not want to close the connection. We drop the msg rather than blocking here.
|
||||||
|
/// If the buffer is full because there is an underlying issue with the peer
|
||||||
|
/// and potentially the peer connection. We assume this will be handled at the peer level.
|
||||||
pub fn send(&self, msg: Msg) -> Result<(), Error> {
|
pub fn send(&self, msg: Msg) -> Result<(), Error> {
|
||||||
self.send_channel.try_send(msg)?;
|
match self.send_channel.try_send(msg) {
|
||||||
Ok(())
|
Ok(()) => Ok(()),
|
||||||
|
Err(mpsc::TrySendError::Disconnected(_)) => {
|
||||||
|
Err(Error::Send("try_send disconnected".to_owned()))
|
||||||
|
}
|
||||||
|
Err(mpsc::TrySendError::Full(_)) => {
|
||||||
|
debug!("conn_handle: try_send but buffer is full, dropping msg");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ use std::fs::File;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use std::sync::mpsc;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
@ -106,11 +104,6 @@ impl From<io::Error> for Error {
|
||||||
Error::Connection(e)
|
Error::Connection(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<T> From<mpsc::TrySendError<T>> for Error {
|
|
||||||
fn from(e: mpsc::TrySendError<T>) -> Error {
|
|
||||||
Error::Send(e.to_string())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||||
pub struct PeerAddr(pub SocketAddr);
|
pub struct PeerAddr(pub SocketAddr);
|
||||||
|
|
Loading…
Reference in a new issue