Repository navigation
fix(diagnostics,minimald): re-pin socket-join pids and make the diag stream timeout idle-based #927
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,12 +61,15 @@ const MAX_SESSION_FILE_BYTES: u64 = 8 * 1024 * 1024; | |
| const LOG_FILES_MAX: usize = 5; | ||
| /// Entry cap for the recursive state-dir listing. | ||
| const LISTING_MAX_ENTRIES: usize = 100_000; | ||
| /// Ceiling on the whole client-facing transfer. Every collector is deadlined | ||
| /// individually, but those deadlines only bound work — a client that holds the | ||
| /// channel open and stops reading it parks the pump instead, and through the | ||
| /// bounded duplex that stalls collection and finalization behind it. This is | ||
| /// the bound on the peer rather than on ourselves. | ||
| const STREAM_TIMEOUT: Duration = Duration::from_secs(300); | ||
| /// How long a single write to the client may stall before the stream is | ||
| /// abandoned. This bounds a *non-reading* peer, not total transfer time: the | ||
| /// pump resets it on every write that makes progress, so a slow-but-advancing | ||
| /// build — up to fifteen 30s [`diagnostics::COLLECTOR_TIMEOUT`] collectors, | ||
| /// ~450s worst case — streams to completion, while a client that stops | ||
| /// draining the channel (backpressure fills the duplex and parks the next | ||
| /// write) trips it. A whole-transfer wall-clock cap, by contrast, would kill a | ||
| /// legitimate slow run and wrongly blame the client for it. | ||
| const STREAM_IDLE_TIMEOUT: Duration = Duration::from_secs(60); | ||
|
Comment on lines
+64
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
cargo tree -i tokio
rg -n 'poll_write|WriteAll' \
"${CARGO_HOME:-$HOME/.cargo}/registry/src" \
--glob '*/tokio-*/src/io/util/write_all.rs'Repository: gominimal/minimal Length of output: 147 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '--- crates/minimald/src/diag.rs (relevant lines) ---\n'
sed -n '150,220p' crates/minimald/src/diag.rs
printf '\n--- tokio version in this repo ---\n'
cargo metadata --no-deps --format-version 1 | python3 - <<'PY'
import json,sys
m=json.load(sys.stdin)
for p in m["packages"]:
if p["name"]=="tokio":
print(p["name"], p["version"])
PY
printf '\n--- tokio write_all source if present in cargo registry ---\n'
python3 - <<'PY'
import os,glob,sys
home=os.environ.get("CARGO_HOME", os.path.expanduser("~/.cargo"))
paths=glob.glob(home+"/registry/src/*/tokio-*/src/io/util/write_all.rs")
print("\n".join(paths) if paths else "NOT_FOUND")
PYRepository: gominimal/minimal Length of output: 246 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Locate the exact call site and surrounding logic.
rg -n 'write_all|timeout\(STREAM_IDLE_TIMEOUT|STREAM_IDLE_TIMEOUT' crates/minimald/src/diag.rs -n -A8 -B8
# Find any local guidance on Tokio or diagnostics behavior.
rg -n 'diagnostics::COLLECTOR_TIMEOUT|STREAM_IDLE_TIMEOUT|write_all' crates -g '!**/target/**'Repository: gominimal/minimal Length of output: 22091 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Read Tokio's write_all implementation from the local cargo registry if present.
python3 - <<'PY'
import os,glob
home=os.environ.get("CARGO_HOME", os.path.expanduser("~/.cargo"))
matches=glob.glob(home+"/registry/src/*/tokio-*/src/io/util/write_all.rs")
if not matches:
print("NO_TOKIO_SOURCE")
else:
print(matches[0])
PYRepository: gominimal/minimal Length of output: 171 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '--- diag.rs excerpt ---'
sed -n '160,210p' crates/minimald/src/diag.rs
echo
echo '--- tokio version from Cargo.lock ---'
rg -n '^name = "tokio"|^version = ' Cargo.lock -A1 -B1
echo
echo '--- local tokio write_all implementation path(s) ---'
python3 - <<'PY'
import os,glob
home=os.environ.get("CARGO_HOME", os.path.expanduser("~/.cargo"))
paths=glob.glob(home+"/registry/src/*/tokio-*/src/io/util/write_all.rs")
for p in paths:
print(p)
PYRepository: gominimal/minimal Length of output: 50373 🌐 Web query:
💡 Result: Tokio's Citations:
Reset the deadline per write. 🤖 Prompt for AI Agents |
||
| /// Duplex buffer between the bundle writer and the channel pump. | ||
| const PIPE_BUF: usize = 256 * 1024; | ||
| /// The gvproxy management endpoint, reachable only from inside the switch | ||
|
|
@@ -155,18 +158,35 @@ async fn stream_diag_bundle(s: &ServerStateHandle, c: &mut RuChannel<Msg>) -> Re | |
| }; | ||
|
|
||
| let mut writer = c.make_writer(); | ||
| // Bounded here rather than around the build: cancelling the pump is safe, | ||
| // cancelling the builder is not (see `build_bundle`). On expiry the `drop` | ||
| // below turns the build task's next write into `BrokenPipe`, so it unwinds | ||
| // through its own error path instead of parking on the full duplex. | ||
| let copy_result = | ||
| match tokio::time::timeout(STREAM_TIMEOUT, tokio::io::copy(&mut rx, &mut writer)).await { | ||
| Ok(r) => r, | ||
| Err(_) => Err(std::io::Error::new( | ||
| std::io::ErrorKind::TimedOut, | ||
| format!("client stopped reading the bundle for {STREAM_TIMEOUT:?}"), | ||
| )), | ||
| // A hand-rolled pump so the deadline is per-write, not whole-transfer: | ||
| // reading from the build task is left unbounded (its collectors self-bound | ||
| // via `COLLECTOR_TIMEOUT`, so a slow-but-progressing build must not be | ||
| // killed), while each write to the client is bounded. A stalled write means | ||
| // the client stopped draining the channel — backpressure that fills the | ||
| // duplex and parks collection behind it — which is the non-reading-client | ||
| // DoS this bound exists for. The bound is on the pump rather than the build | ||
| // because cancelling the pump is safe and cancelling the builder is not | ||
| // (see `build_bundle`): on a stall the `drop` below turns the build task's | ||
| // next write into `BrokenPipe`, so it unwinds through its own error path | ||
| // instead of parking on the full duplex. | ||
| let mut buf = vec![0u8; PIPE_BUF]; | ||
| let copy_result = loop { | ||
| let n = match rx.read(&mut buf).await { | ||
| Ok(0) => break Ok(()), // EOF: the build task finished and dropped tx. | ||
| Ok(n) => n, | ||
| Err(e) => break Err(e), | ||
| }; | ||
| match tokio::time::timeout(STREAM_IDLE_TIMEOUT, writer.write_all(&buf[..n])).await { | ||
| Ok(Ok(())) => {} | ||
| Ok(Err(e)) => break Err(e), | ||
| Err(_) => { | ||
| break Err(std::io::Error::new( | ||
| std::io::ErrorKind::TimedOut, | ||
| format!("client read no bundle data for {STREAM_IDLE_TIMEOUT:?}"), | ||
| )); | ||
| } | ||
| } | ||
| }; | ||
| let shutdown_result = writer.shutdown().await; | ||
| // The read half must be gone before waiting on the build task: if the copy | ||
| // failed mid-stream (client vanished) the task is still writing, and only a | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Handle an empty set after re-pinning.
When all snapshot PIDs are stale,
repin_livereturns an empty vector, butsocket_joinstill builds/proc/nettables and emits a header-only file instead of callingw.skip(...). Add the same empty check immediately after Line 437.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents