Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: the cpuload 100% in case the tcpstream WouldBlock #3029

Merged
merged 3 commits into from
Sep 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions p2p/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ macro_rules! try_break {
($inner:expr) => {
match $inner {
Ok(v) => Some(v),
Err(Error::Connection(ref e))
if e.kind() == io::ErrorKind::WouldBlock || e.kind() == io::ErrorKind::TimedOut =>
{
Err(Error::Connection(ref e)) if e.kind() == io::ErrorKind::TimedOut => None,
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
}
Err(Error::Store(_))
Expand Down Expand Up @@ -375,7 +376,7 @@ where
})?;

let writer_thread = thread::Builder::new()
.name("peer_read".to_string())
.name("peer_write".to_string())
.spawn(move || {
let mut retry_send = Err(());
loop {
Expand All @@ -394,7 +395,7 @@ where
}

debug!(
"Shutting down reader connection with {}",
"Shutting down writer connection with {}",
writer
.peer_addr()
.map(|a| a.to_string())
Expand Down