Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.

Commit 2000e50

Browse files
authored
add missing toploc timeout (#434)
* add missing toploc timeout
1 parent da38d73 commit 2000e50

1 file changed

Lines changed: 47 additions & 42 deletions

File tree

  • crates/validator/src/validators/synthetic_data

crates/validator/src/validators/synthetic_data/toploc.rs

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ impl Toploc {
4343
}
4444
headers
4545
})
46+
.timeout(std::time::Duration::from_secs(30))
47+
.connect_timeout(std::time::Duration::from_secs(10))
4648
.build()
4749
.expect("Failed to build HTTP client");
4850

@@ -145,14 +147,24 @@ impl Toploc {
145147
Ok(())
146148
}
147149
Err(e) => {
148-
error!(
149-
"Failed to trigger remote toploc validation for {}: {}",
150-
file_name, e
151-
);
150+
let error_msg = if e.is_timeout() {
151+
format!("Toploc request timed out for {}: {}", file_name, e)
152+
} else if e.is_connect() {
153+
format!(
154+
"Failed to connect to toploc server for {}: {}",
155+
file_name, e
156+
)
157+
} else {
158+
format!(
159+
"Failed to trigger remote toploc validation for {}: {}",
160+
file_name, e
161+
)
162+
};
163+
error!("{}", error_msg);
152164
if let Some(metrics) = &self.metrics {
153165
metrics.record_api_request("toploc_single_file_validation", "0");
154166
}
155-
Err(Error::msg(format!("Failed to trigger validation: {}", e)))
167+
Err(Error::msg(error_msg))
156168
}
157169
}
158170
}
@@ -216,17 +228,24 @@ impl Toploc {
216228
Ok(())
217229
}
218230
Err(e) => {
219-
error!(
220-
"Failed to trigger remote toploc group validation for {}: {}",
221-
file_name, e
222-
);
231+
let error_msg = if e.is_timeout() {
232+
format!("Toploc group request timed out for {}: {}", file_name, e)
233+
} else if e.is_connect() {
234+
format!(
235+
"Failed to connect to toploc server for group {}: {}",
236+
file_name, e
237+
)
238+
} else {
239+
format!(
240+
"Failed to trigger remote toploc group validation for {}: {}",
241+
file_name, e
242+
)
243+
};
244+
error!("{}", error_msg);
223245
if let Some(metrics) = &self.metrics {
224246
metrics.record_api_request("toploc_group_file_validation", "0");
225247
}
226-
Err(Error::msg(format!(
227-
"Failed to trigger group validation: {}",
228-
e
229-
)))
248+
Err(Error::msg(error_msg))
230249
}
231250
}
232251
}
@@ -313,14 +332,21 @@ impl Toploc {
313332
}
314333
}
315334
Err(e) => {
316-
error!(
317-
"Failed to poll remote toploc group validation for {}: {}",
318-
file_name, e
319-
);
320-
Err(Error::msg(format!(
321-
"Failed to poll remote toploc group validation: {}",
322-
e
323-
)))
335+
let error_msg = if e.is_timeout() {
336+
format!("Toploc status check timed out for {}: {}", file_name, e)
337+
} else if e.is_connect() {
338+
format!(
339+
"Failed to connect to toploc server for status check {}: {}",
340+
file_name, e
341+
)
342+
} else {
343+
format!(
344+
"Failed to poll remote toploc group validation for {}: {}",
345+
file_name, e
346+
)
347+
};
348+
error!("{}", error_msg);
349+
Err(Error::msg(error_msg))
324350
}
325351
}
326352
}
@@ -758,27 +784,6 @@ mod tests {
758784
Ok(())
759785
}
760786

761-
#[tokio::test]
762-
async fn test_network_timeout_error() -> Result<(), Error> {
763-
// Test with an invalid/unreachable URL to simulate network errors
764-
let config = ToplocConfig {
765-
server_url: "http://localhost:99999".to_string(), // Invalid port
766-
auth_token: None,
767-
file_prefix_filter: None,
768-
};
769-
let toploc = Toploc::new(config, None);
770-
771-
let result = toploc
772-
.trigger_single_file_validation("abc123", "0x456", "test.parquet")
773-
.await;
774-
775-
assert!(result.is_err());
776-
assert!(result
777-
.unwrap_err()
778-
.to_string()
779-
.contains("Failed to trigger validation"));
780-
Ok(())
781-
}
782787
#[tokio::test]
783788
async fn test_group_validation_with_auth_token() -> Result<(), Error> {
784789
let mut server = Server::new_async().await;

0 commit comments

Comments
 (0)