Repository: quinn-rs/quinn (Rust)

Issue:
quinn-proto: `Endpoint::connect` retrieves timestamp from OS
While debugging an issue I was running into, I found that `quinn_proto::Endpoint::connect` fetches a timestamp from the OS: 
https://github.com/quinn-rs/quinn/blob/7f260292848a93d615eb43e6e88114a97e64daf1/quinn-proto/src/endpoint.rs#L355

I would have expected `Endpoint::connect` to take in a `now: Instant` parameter instead. I got that impression from the [crate docs](https://github.com/quinn-rs/quinn/blob/7f260292848a93d615eb43e6e88114a97e64daf1/quinn-proto/src/lib.rs#L3C5-L5).

Is this intended behavior?


Thanks for your help!


Discussion:
Nope, I think this is an oversight -- thanks for reporting! I checked for `Instant::now` calls in quinn-proto and found that this was the only one that doesn't uphold the documented contract. There is one other one in the BBR bandwidth estimator, but it has a comment saying that the value will be overwritten before it is used -- all the remaining instances are in test code.

Fix submitted in #1649.



Patch:
diff --git a/Cargo.toml b/Cargo.toml
index 6a985fb62b..f90603ec03 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,7 @@
 [workspace]
 members = ["quinn", "quinn-proto", "quinn-udp", "bench", "perf", "fuzz"]
 default-members = ["quinn", "quinn-proto", "quinn-udp", "bench", "perf"]
+resolver = "2"
 
 [profile.bench]
 debug = true
diff --git a/quinn-proto/src/endpoint.rs b/quinn-proto/src/endpoint.rs
index 1200aaf85e..3e0719369d 100644
--- a/quinn-proto/src/endpoint.rs
+++ b/quinn-proto/src/endpoint.rs
@@ -312,6 +312,7 @@ impl Endpoint {
     /// Initiate a connection
     pub fn connect(
         &mut self,
+        now: Instant,
         config: ClientConfig,
         remote: SocketAddr,
         server_name: &str,
@@ -352,7 +353,7 @@ impl Endpoint {
                 remote,
                 local_ip: None,
             },
-            Instant::now(),
+            now,
             tls,
             None,
             config.transport,
diff --git a/quinn-proto/src/range_set/btree_range_set.rs b/quinn-proto/src/range_set/btree_range_set.rs
index 18d24ff196..8114cf146b 100644
--- a/quinn-proto/src/range_set/btree_range_set.rs
+++ b/quinn-proto/src/range_set/btree_range_set.rs
@@ -321,6 +321,7 @@ impl Drop for Replace<'_> {
 /// Tests which apply for all implementations can be found in the `tests.rs` module
 #[cfg(test)]
 mod tests {
+    #![allow(clippy::single_range_in_vec_init)] // https://github.com/rust-lang/rust-clippy/issues/11086
     use super::*;
 
     #[test]
diff --git a/quinn/src/endpoint.rs b/quinn/src/endpoint.rs
index f6252604f4..429afbb9a9 100644
--- a/quinn/src/endpoint.rs
+++ b/quinn/src/endpoint.rs
@@ -186,7 +186,11 @@ impl Endpoint {
         } else {
             addr
         };
-        let (ch, conn) = endpoint.inner.connect(config, addr, server_name)?;
+
+        let (ch, conn) = endpoint
+            .inner
+            .connect(Instant::now(), config, addr, server_name)?;
+
         let socket = endpoint.socket.clone();
         Ok(endpoint
             .connections


Test patch:
diff --git a/quinn-proto/src/tests/mod.rs b/quinn-proto/src/tests/mod.rs
index 21eb9a0508..7d66397134 100644
--- a/quinn-proto/src/tests/mod.rs
+++ b/quinn-proto/src/tests/mod.rs
@@ -37,7 +37,9 @@ fn version_negotiate_server() {
         // Long-header packet with reserved version number
         hex!("80 0a1a2a3a 04 00000000 04 00000000 00")[..].into(),
     );
-    let Some(DatagramEvent::Response(Transmit { contents, .. })) = event else { panic!("expected a response"); };
+    let Some(DatagramEvent::Response(Transmit { contents, .. })) = event else {
+        panic!("expected a response");
+    };
 
     assert_ne!(contents[0] & 0x80, 0);
     assert_eq!(&contents[1..15], hex!("00000000 04 00000000 04 00000000"));
@@ -63,7 +65,7 @@ fn version_negotiate_client() {
         true,
     );
     let (_, mut client_ch) = client
-        .connect(client_config(), server_addr, "localhost")
+        .connect(Instant::now(), client_config(), server_addr, "localhost")
         .unwrap();
     let now = Instant::now();
     let opt_event = client.handle(
diff --git a/quinn-proto/src/tests/util.rs b/quinn-proto/src/tests/util.rs
index 4e38e4a813..73e4b2e78f 100644
--- a/quinn-proto/src/tests/util.rs
+++ b/quinn-proto/src/tests/util.rs
@@ -201,7 +201,7 @@ impl Pair {
         let _guard = span.enter();
         let (client_ch, client_conn) = self
             .client
-            .connect(config, self.server.addr, "localhost")
+            .connect(Instant::now(), config, self.server.addr, "localhost")
             .unwrap();
         self.client.connections.insert(client_ch, client_conn);
         client_ch