@@ -18,6 +18,9 @@ use std::io::Read;
18
18
#[ cfg( not( feature = "tokio" ) ) ]
19
19
use std:: net:: TcpStream ;
20
20
21
+ /// Timeout for operations on TCP streams.
22
+ const TCP_STREAM_TIMEOUT : Duration = Duration :: from_secs ( 5 ) ;
23
+
21
24
/// Maximum HTTP message header size in bytes.
22
25
const MAX_HTTP_MESSAGE_HEADER_SIZE : usize = 8192 ;
23
26
@@ -95,9 +98,9 @@ impl HttpClient {
95
98
} ,
96
99
Some ( address) => address,
97
100
} ;
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 ) ) ?;
101
104
102
105
#[ cfg( feature = "tokio" ) ]
103
106
let stream = {
@@ -512,7 +515,7 @@ pub(crate) mod client_tests {
512
515
let handler = std:: thread:: spawn ( move || {
513
516
for stream in listener. incoming ( ) {
514
517
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 ( ) ;
516
519
517
520
let lines_read = std:: io:: BufReader :: new ( & stream)
518
521
. lines ( )
0 commit comments