mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 17:01:09 +03:00
fix: the cpuload 100% in case the tcpstream WouldBlock (#3029)
* fix: the cpuload 100% in case the tcpstream WouldBlock * extending the sleep on WouldBlock to all read/write * rustfmt
This commit is contained in:
parent
7a07541c26
commit
4faac470d4
1 changed files with 6 additions and 5 deletions
|
@ -58,9 +58,10 @@ macro_rules! try_break {
|
||||||
($inner:expr) => {
|
($inner:expr) => {
|
||||||
match $inner {
|
match $inner {
|
||||||
Ok(v) => Some(v),
|
Ok(v) => Some(v),
|
||||||
Err(Error::Connection(ref e))
|
Err(Error::Connection(ref e)) if e.kind() == io::ErrorKind::TimedOut => None,
|
||||||
if e.kind() == io::ErrorKind::WouldBlock || e.kind() == io::ErrorKind::TimedOut =>
|
Err(Error::Connection(ref e)) if e.kind() == io::ErrorKind::WouldBlock => {
|
||||||
{
|
// to avoid the heavy polling which will consume CPU 100%
|
||||||
|
thread::sleep(Duration::from_millis(10));
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
Err(Error::Store(_))
|
Err(Error::Store(_))
|
||||||
|
@ -375,7 +376,7 @@ where
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let writer_thread = thread::Builder::new()
|
let writer_thread = thread::Builder::new()
|
||||||
.name("peer_read".to_string())
|
.name("peer_write".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
let mut retry_send = Err(());
|
let mut retry_send = Err(());
|
||||||
loop {
|
loop {
|
||||||
|
@ -394,7 +395,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"Shutting down reader connection with {}",
|
"Shutting down writer connection with {}",
|
||||||
writer
|
writer
|
||||||
.peer_addr()
|
.peer_addr()
|
||||||
.map(|a| a.to_string())
|
.map(|a| a.to_string())
|
||||||
|
|
Loading…
Reference in a new issue