Skip to content

Commit 37e4ece

Browse files
committed
add heartbeat log
1 parent cd9bbab commit 37e4ece

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

stackslib/src/net/httpcore.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ pub const STACKS_REQUEST_ID: &str = "X-Request-Id";
7070
/// from non-Stacks nodes (like Gaia hubs, CDNs, vanilla HTTP servers, and so on).
7171
pub const HTTP_REQUEST_ID_RESERVED: u32 = 0;
7272

73+
/// The interval at which to send heartbeat logs
74+
const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(60);
75+
7376
/// All representations of the `tip=` query parameter value
7477
#[derive(Debug, Clone, PartialEq)]
7578
pub enum TipRequest {
@@ -1823,8 +1826,8 @@ pub fn send_http_request(
18231826
stream.set_nodelay(true)?;
18241827

18251828
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);
18281831

18291832
// Some explanation of what's going on here is in order.
18301833
//
@@ -1882,6 +1885,7 @@ pub fn send_http_request(
18821885
.map_err(|e| handle_net_error(e, "Failed to serialize request body"))?;
18831886

18841887
debug!("send_request(sending data)");
1888+
let mut last_heartbeat_time = start; // Initialize heartbeat timer for sending loop
18851889
loop {
18861890
let flushed = request_handle
18871891
.try_flush()
@@ -1906,12 +1910,21 @@ pub fn send_http_request(
19061910
"Timed out while receiving request",
19071911
));
19081912
}
1913+
// Heartbeat log
1914+
if Instant::now().saturating_duration_since(last_heartbeat_time) >= HEARTBEAT_INTERVAL {
1915+
info!(
1916+
"send_request(sending data): heartbeat - still sending request to {} path='{}' (elapsed: {:?})",
1917+
addr, request_path, start.elapsed()
1918+
);
1919+
last_heartbeat_time = Instant::now();
1920+
}
19091921
}
19101922

19111923
// Step 4: pull bytes from the socket back into the handle, and see if the connection decoded
19121924
// and dispatched any new messages to the request handle. If so, then extract the message and
19131925
// check that it's a well-formed HTTP response.
19141926
debug!("send_request(receiving data)");
1927+
last_heartbeat_time = Instant::now();
19151928
let response = loop {
19161929
// get back the reply
19171930
debug!("send_request(receiving data): try to receive data");
@@ -1950,6 +1963,14 @@ pub fn send_http_request(
19501963
"Timed out while receiving request",
19511964
));
19521965
}
1966+
// Heartbeat log
1967+
if Instant::now().saturating_duration_since(last_heartbeat_time) >= HEARTBEAT_INTERVAL {
1968+
info!(
1969+
"send_request(receiving data): heartbeat - still receiving response from {} path='{}' (elapsed: {:?})",
1970+
addr, request_path, start.elapsed()
1971+
);
1972+
last_heartbeat_time = Instant::now();
1973+
}
19531974
};
19541975

19551976
// Step 5: decode the HTTP message and return it if it's not an error.

0 commit comments

Comments
 (0)