@@ -70,6 +70,9 @@ pub const STACKS_REQUEST_ID: &str = "X-Request-Id";
70
70
/// from non-Stacks nodes (like Gaia hubs, CDNs, vanilla HTTP servers, and so on).
71
71
pub const HTTP_REQUEST_ID_RESERVED : u32 = 0 ;
72
72
73
+ /// The interval at which to send heartbeat logs
74
+ const HEARTBEAT_INTERVAL : Duration = Duration :: from_secs ( 60 ) ;
75
+
73
76
/// All representations of the `tip=` query parameter value
74
77
#[ derive( Debug , Clone , PartialEq ) ]
75
78
pub enum TipRequest {
@@ -1823,8 +1826,8 @@ pub fn send_http_request(
1823
1826
stream. set_nodelay ( true ) ?;
1824
1827
1825
1828
let start = Instant :: now ( ) ;
1826
-
1827
- debug ! ( "send_request: Sending request" ; "request" => %request . request_path( ) ) ;
1829
+ let request_path = request . request_path ( ) ;
1830
+ debug ! ( "send_request: Sending request" ; "request" => request_path) ;
1828
1831
1829
1832
// Some explanation of what's going on here is in order.
1830
1833
//
@@ -1882,6 +1885,7 @@ pub fn send_http_request(
1882
1885
. map_err ( |e| handle_net_error ( e, "Failed to serialize request body" ) ) ?;
1883
1886
1884
1887
debug ! ( "send_request(sending data)" ) ;
1888
+ let mut last_heartbeat_time = start; // Initialize heartbeat timer for sending loop
1885
1889
loop {
1886
1890
let flushed = request_handle
1887
1891
. try_flush ( )
@@ -1900,18 +1904,26 @@ pub fn send_http_request(
1900
1904
break ;
1901
1905
}
1902
1906
1903
- if Instant :: now ( ) . saturating_duration_since ( start ) > timeout {
1907
+ if start . elapsed ( ) >= timeout {
1904
1908
return Err ( io:: Error :: new (
1905
1909
io:: ErrorKind :: WouldBlock ,
1906
- "Timed out while receiving request" ,
1910
+ "Timed out while sending request" ,
1907
1911
) ) ;
1908
1912
}
1913
+ if last_heartbeat_time. elapsed ( ) >= HEARTBEAT_INTERVAL {
1914
+ info ! (
1915
+ "send_request(sending data): heartbeat - still sending request to {} path='{}' (elapsed: {:?})" ,
1916
+ addr, request_path, start. elapsed( )
1917
+ ) ;
1918
+ last_heartbeat_time = Instant :: now ( ) ;
1919
+ }
1909
1920
}
1910
1921
1911
1922
// Step 4: pull bytes from the socket back into the handle, and see if the connection decoded
1912
1923
// and dispatched any new messages to the request handle. If so, then extract the message and
1913
1924
// check that it's a well-formed HTTP response.
1914
1925
debug ! ( "send_request(receiving data)" ) ;
1926
+ last_heartbeat_time = Instant :: now ( ) ;
1915
1927
let response = loop {
1916
1928
// get back the reply
1917
1929
debug ! ( "send_request(receiving data): try to receive data" ) ;
@@ -1944,12 +1956,19 @@ pub fn send_http_request(
1944
1956
} ;
1945
1957
request_handle = rh;
1946
1958
1947
- if Instant :: now ( ) . saturating_duration_since ( start ) > timeout {
1959
+ if start . elapsed ( ) >= timeout {
1948
1960
return Err ( io:: Error :: new (
1949
1961
io:: ErrorKind :: WouldBlock ,
1950
- "Timed out while receiving request " ,
1962
+ "Timed out while receiving response " ,
1951
1963
) ) ;
1952
1964
}
1965
+ if last_heartbeat_time. elapsed ( ) >= HEARTBEAT_INTERVAL {
1966
+ info ! (
1967
+ "send_request(receiving data): heartbeat - still receiving response from {} path='{}' (elapsed: {:?})" ,
1968
+ addr, request_path, start. elapsed( )
1969
+ ) ;
1970
+ last_heartbeat_time = Instant :: now ( ) ;
1971
+ }
1953
1972
} ;
1954
1973
1955
1974
// Step 5: decode the HTTP message and return it if it's not an error.
0 commit comments