Skip to content

Commit 343b14a

Browse files
committed
f - Increase TCP timeout to avoid test deadlock
1 parent 70d12a0 commit 343b14a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lightning-block-sync/src/http.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ use std::io::Read;
1818
#[cfg(not(feature = "tokio"))]
1919
use std::net::TcpStream;
2020

21+
/// Timeout for operations on TCP streams.
22+
const TCP_STREAM_TIMEOUT: Duration = Duration::from_secs(5);
23+
2124
/// Maximum HTTP message header size in bytes.
2225
const MAX_HTTP_MESSAGE_HEADER_SIZE: usize = 8192;
2326

@@ -95,9 +98,9 @@ impl HttpClient {
9598
},
9699
Some(address) => address,
97100
};
98-
let stream = std::net::TcpStream::connect_timeout(&address, Duration::from_secs(1))?;
99-
stream.set_read_timeout(Some(Duration::from_secs(2)))?;
100-
stream.set_write_timeout(Some(Duration::from_secs(1)))?;
101+
let stream = std::net::TcpStream::connect_timeout(&address, TCP_STREAM_TIMEOUT)?;
102+
stream.set_read_timeout(Some(TCP_STREAM_TIMEOUT))?;
103+
stream.set_write_timeout(Some(TCP_STREAM_TIMEOUT))?;
101104

102105
#[cfg(feature = "tokio")]
103106
let stream = {
@@ -512,7 +515,7 @@ pub(crate) mod client_tests {
512515
let handler = std::thread::spawn(move || {
513516
for stream in listener.incoming() {
514517
let mut stream = stream.unwrap();
515-
stream.set_write_timeout(Some(Duration::from_secs(1))).unwrap();
518+
stream.set_write_timeout(Some(TCP_STREAM_TIMEOUT)).unwrap();
516519

517520
let lines_read = std::io::BufReader::new(&stream)
518521
.lines()

0 commit comments

Comments
 (0)