Skip to content

Commit a749ac3

Browse files
authored
bug: apply request_timeout to timeout_connect (#72)
1 parent 7556ecb commit a749ac3

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

questdb-rs/src/ingress/mod.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1919,7 +1919,7 @@ impl SenderBuilder {
19191919
}
19201920

19211921
/// Configure how long to wait for messages from the QuestDB server during
1922-
/// the TLS handshake and authentication process.
1922+
/// the TLS handshake and authentication process. This only applies to TCP.
19231923
/// The default is 15 seconds.
19241924
pub fn auth_timeout(mut self, value: Duration) -> Result<Self> {
19251925
self.auth_timeout.set_specified("auth_timeout", value)?;
@@ -2016,6 +2016,8 @@ impl SenderBuilder {
20162016
/// The timeout calculated from minimum throughput is adedd to the value of
20172017
/// [`request_timeout`](SenderBuilder::request_timeout) to get the total timeout
20182018
/// value.
2019+
/// A value of 0 disables this feature, so it's similar to setting "infinite"
2020+
/// minimum throughput. The total timeout will then be equal to `request_timeout`.
20192021
pub fn request_min_throughput(mut self, value: u64) -> Result<Self> {
20202022
if let Some(http) = &mut self.http {
20212023
http.request_min_throughput
@@ -2275,7 +2277,8 @@ impl SenderBuilder {
22752277
));
22762278
}
22772279

2278-
let user_agent = self.http.as_ref().unwrap().user_agent.as_str();
2280+
let http_config = self.http.as_ref().unwrap();
2281+
let user_agent = http_config.user_agent.as_str();
22792282
let agent_builder = ureq::AgentBuilder::new()
22802283
.user_agent(user_agent)
22812284
.no_delay(true);
@@ -2307,6 +2310,8 @@ impl SenderBuilder {
23072310
}
23082311
None => None,
23092312
};
2313+
let agent_builder =
2314+
agent_builder.timeout_connect(*http_config.request_timeout.deref());
23102315
let agent = agent_builder.build();
23112316
let proto = self.protocol.schema();
23122317
let url = format!(

questdb-rs/src/ingress/tests.rs

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::time::Instant;
2+
13
use super::*;
24
use crate::ErrorCode;
35
use tempfile::TempDir;
@@ -398,6 +400,32 @@ fn http_retry_timeout() {
398400
assert_specified_eq(&http_config.retry_timeout, Duration::from_millis(100));
399401
}
400402

403+
#[cfg(feature = "ilp-over-http")]
404+
#[test]
405+
fn connect_timeout_uses_request_timeout() {
406+
let request_timeout = Duration::from_millis(10);
407+
let builder = SenderBuilder::new(Protocol::Http, "127.0.0.2", "1111")
408+
.request_timeout(request_timeout)
409+
.unwrap()
410+
.retry_timeout(Duration::from_millis(10))
411+
.unwrap()
412+
.request_min_throughput(0)
413+
.unwrap();
414+
let mut sender = builder.build().unwrap();
415+
let mut buf = Buffer::new();
416+
buf.table("x")
417+
.unwrap()
418+
.symbol("x", "x")
419+
.unwrap()
420+
.at_now()
421+
.unwrap();
422+
let start = Instant::now();
423+
sender
424+
.flush(&mut buf)
425+
.expect_err("Request did not time out");
426+
assert!(Instant::now() - start < Duration::from_secs(10));
427+
}
428+
401429
#[test]
402430
fn auto_flush_off() {
403431
SenderBuilder::from_conf("tcps::addr=localhost;auto_flush=off;").unwrap();

questdb-rs/src/tests/http.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,12 @@ fn test_request_timeout() -> TestResult {
441441
assert!(res.is_err());
442442
let err = res.unwrap_err();
443443
assert_eq!(err.code(), ErrorCode::SocketError);
444-
assert!(err.msg().contains("timed out reading response"));
444+
// different error message on windows
445+
if cfg!(windows) {
446+
assert!(err.msg().contains("os error 10060"));
447+
} else {
448+
assert!(err.msg().contains("timed out reading response"));
449+
}
445450
assert!(time_elapsed >= request_timeout);
446451
Ok(())
447452
}
@@ -628,7 +633,7 @@ fn test_one_retry() -> TestResult {
628633
return Err(io::Error::new(
629634
ErrorKind::InvalidInput,
630635
"unexpected retry response",
631-
))
636+
));
632637
}
633638
Err(err) => err,
634639
};

questdb-rs/src/tests/sender.rs

-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ fn bad_uppercase_addr() {
484484
let res = Sender::from_conf("tcp::ADDR=localhost:9009;");
485485
assert!(res.is_err());
486486
let err = res.unwrap_err();
487-
eprint!("err: {:?}", err);
488487
assert!(err.code() == ErrorCode::ConfigError);
489488
assert!(err.msg() == "Missing \"addr\" parameter in config string");
490489
}

0 commit comments

Comments
 (0)