Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
pinger = { git = "https://github.com/orf/gping", package = "pinger" }
reqwest.workspace = true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo.toml syntax is invalid here. The workspace override must be expressed as an inline table (reqwest = { workspace = true }); using the dotted key form without first declaring [dependencies.reqwest] will cause cargo metadata to fail to parse the manifest.

Prompt for AI agents
Address the following comment on crates/network/Cargo.toml at line 8:

<comment>Cargo.toml syntax is invalid here. The workspace override must be expressed as an inline table (`reqwest = { workspace = true }`); using the dotted key form without first declaring `[dependencies.reqwest]` will cause `cargo metadata` to fail to parse the manifest.</comment>

<file context>
@@ -5,3 +5,4 @@ edition = &quot;2021&quot;
 
 [dependencies]
 pinger = { git = &quot;https://github.com/orf/gping&quot;, package = &quot;pinger&quot; }
+reqwest.workspace = true
</file context>
Suggested change
reqwest.workspace = true
reqwest = { workspace = true }

25 changes: 13 additions & 12 deletions crates/network/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use reqwest::Client;
use std::time::Duration;

pub async fn is_online() -> bool {
let target = "8.8.8.8".to_string();
let interval = std::time::Duration::from_secs(1);
let options = pinger::PingOptions::new(target, interval, None);
let client = Client::builder()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fresh Client is built on every is_online call, defeating reqwest’s connection-pool reuse and introducing overhead. Prefer reusing a single Client instance or passing one in.

Prompt for AI agents
Address the following comment on crates/network/src/lib.rs at line 5:

<comment>A fresh `Client` is built on every `is_online` call, defeating reqwest’s connection-pool reuse and introducing overhead. Prefer reusing a single `Client` instance or passing one in.</comment>

<file context>
@@ -1,16 +1,17 @@
+use reqwest::Client;
+use std::time::Duration;
+
 pub async fn is_online() -&gt; bool {
-    let target = &quot;8.8.8.8&quot;.to_string();
-    let interval = std::time::Duration::from_secs(1);
-    let options = pinger::PingOptions::new(target, interval, None);
+    let client = Client::builder()
+        .timeout(Duration::from_secs(8))
</file context>

.timeout(Duration::from_secs(8))
.build()
.unwrap();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling unwrap() will panic if the Client build fails (e.g., invalid TLS config). A networking utility should not bring down the application on recoverable errors; bubble the error or return false instead.

Prompt for AI agents
Address the following comment on crates/network/src/lib.rs at line 8:

<comment>Calling `unwrap()` will panic if the `Client` build fails (e.g., invalid TLS config). A networking utility should not bring down the application on recoverable errors; bubble the error or return `false` instead.</comment>

<file context>
@@ -1,16 +1,17 @@
+use reqwest::Client;
+use std::time::Duration;
+
 pub async fn is_online() -&gt; bool {
-    let target = &quot;8.8.8.8&quot;.to_string();
-    let interval = std::time::Duration::from_secs(1);
-    let options = pinger::PingOptions::new(target, interval, None);
+    let client = Client::builder()
+        .timeout(Duration::from_secs(8))
</file context>


if let Ok(stream) = pinger::ping(options) {
if let Some(message) = stream.into_iter().next() {
match message {
pinger::PingResult::Pong(_, _) => return true,
_ => return false,
}
}
}

false
let url = "https://posthog.com/";

match client.get(url).send().await {
Ok(resp) if resp.status().is_success() => true,
_ => false,
}
}