Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: apply request_timeout to timeout_connect #72

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions questdb-rs/src/ingress/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1919,7 +1919,7 @@ impl SenderBuilder {
}

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

let user_agent = self.http.as_ref().unwrap().user_agent.as_str();
let http_config = self.http.as_ref().unwrap();
let user_agent = http_config.user_agent.as_str();
let agent_builder = ureq::AgentBuilder::new()
.user_agent(user_agent)
.no_delay(true);
Expand Down Expand Up @@ -2307,6 +2310,8 @@ impl SenderBuilder {
}
None => None,
};
let agent_builder =
agent_builder.timeout_connect(*http_config.request_timeout.deref());
let agent = agent_builder.build();
let proto = self.protocol.schema();
let url = format!(
Expand Down
28 changes: 28 additions & 0 deletions questdb-rs/src/ingress/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Instant;

use super::*;
use crate::ErrorCode;
use tempfile::TempDir;
Expand Down Expand Up @@ -398,6 +400,32 @@ fn http_retry_timeout() {
assert_specified_eq(&http_config.retry_timeout, Duration::from_millis(100));
}

#[cfg(feature = "ilp-over-http")]
#[test]
fn connect_timeout_uses_request_timeout() {
let request_timeout = Duration::from_millis(10);
let builder = SenderBuilder::new(Protocol::Http, "127.0.0.2", "1111")
.request_timeout(request_timeout)
.unwrap()
.retry_timeout(Duration::from_millis(10))
.unwrap()
.request_min_throughput(0)
.unwrap();
let mut sender = builder.build().unwrap();
let mut buf = Buffer::new();
buf.table("x")
.unwrap()
.symbol("x", "x")
.unwrap()
.at_now()
.unwrap();
let start = Instant::now();
sender
.flush(&mut buf)
.expect_err("Request did not time out");
assert!(Instant::now() - start < Duration::from_secs(10));
}

#[test]
fn auto_flush_off() {
SenderBuilder::from_conf("tcps::addr=localhost;auto_flush=off;").unwrap();
Expand Down
9 changes: 7 additions & 2 deletions questdb-rs/src/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,12 @@ fn test_request_timeout() -> TestResult {
assert!(res.is_err());
let err = res.unwrap_err();
assert_eq!(err.code(), ErrorCode::SocketError);
assert!(err.msg().contains("timed out reading response"));
// different error message on windows
if cfg!(windows) {
assert!(err.msg().contains("os error 10060"));
} else {
assert!(err.msg().contains("timed out reading response"));
}
assert!(time_elapsed >= request_timeout);
Ok(())
}
Expand Down Expand Up @@ -628,7 +633,7 @@ fn test_one_retry() -> TestResult {
return Err(io::Error::new(
ErrorKind::InvalidInput,
"unexpected retry response",
))
));
}
Err(err) => err,
};
Expand Down
1 change: 0 additions & 1 deletion questdb-rs/src/tests/sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,6 @@ fn bad_uppercase_addr() {
let res = Sender::from_conf("tcp::ADDR=localhost:9009;");
assert!(res.is_err());
let err = res.unwrap_err();
eprint!("err: {:?}", err);
assert!(err.code() == ErrorCode::ConfigError);
assert!(err.msg() == "Missing \"addr\" parameter in config string");
}
Loading