Skip to content

Commit

Permalink
Set different timeouts for read and write
Browse files Browse the repository at this point in the history
  • Loading branch information
philippem committed May 16, 2024
1 parent 22352de commit 97cf7bd
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use crate::util::{HeaderList, DEFAULT_BLOCKHASH};
use crate::errors::*;

// Used for the connection, read and write timeouts
const DAEMON_TIMEOUT: Duration = Duration::from_secs(5);
const DAEMON_CONNECTION_TIMEOUT: Duration = Duration::from_secs(10);

const DAEMON_READ_TIMEOUT: Duration = Duration::from_secs(10*60);
const DAEMON_WRITE_TIMEOUT: Duration = Duration::from_secs(10*60);

fn parse_hash<T>(value: &Value) -> Result<T>
where
Expand Down Expand Up @@ -132,15 +135,15 @@ struct Connection {

fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
loop {
match TcpStream::connect_timeout(&addr, DAEMON_TIMEOUT) {
match TcpStream::connect_timeout(&addr, DAEMON_CONNECTION_TIMEOUT) {
Ok(conn) => {
// can only fail if DAEMON_TIMEOUT is 0
conn.set_read_timeout(Some(DAEMON_TIMEOUT)).unwrap();
conn.set_write_timeout(Some(DAEMON_TIMEOUT)).unwrap();
conn.set_read_timeout(Some(DAEMON_READ_TIMEOUT)).unwrap();
conn.set_write_timeout(Some(DAEMON_WRITE_TIMEOUT)).unwrap();
return Ok(conn);
}
Err(err) => {
warn!("failed to connect daemon at {}: {}", addr, err);
warn!("failed to connect daemon at {}: {} (backoff 3 seconds)", addr, err);
signal.wait(Duration::from_secs(3), false)?;
continue;
}
Expand Down

0 comments on commit 97cf7bd

Please sign in to comment.