Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(personhog): move harness ports out of the ephemeral range (#71099)

Zach Brown828bab7e8363
diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml
index 242f995e09c0..7c60dcd389a0 100644
--- a/.github/workflows/ci-rust.yml
+++ b/.github/workflows/ci-rust.yml
@@ -557,23 +557,17 @@ jobs:
run: cargo test -p personhog-test-harness
- name: Run the e2e gate
- env:
- RUST_BACKTRACE: 1
run: |
./target/debug/personhog-test-harness gate \
--leaders 2 --partitions 4 --persons 100 --concurrency 10 --duration 10s
- name: Run the e2e gate under chaos (kill + scale-up)
- env:
- RUST_BACKTRACE: 1
run: |
./target/debug/personhog-test-harness gate \
--leaders 3 --partitions 8 --persons 100 --concurrency 10 --duration 15s \
--kill-after 5s --scale-up-after 8s
- name: Run the e2e gate under chaos (drain + zombie + writer lag)
- env:
- RUST_BACKTRACE: 1
run: |
./target/debug/personhog-test-harness gate \
--leaders 3 --partitions 8 --persons 100 --concurrency 10 --duration 18s \
@@ -581,8 +575,6 @@ jobs:
--writer-pause-after 4s --writer-pause-duration 6s
- name: Run the e2e gate under chaos (TTL-expiry kill + restarts)
- env:
- RUST_BACKTRACE: 1
run: |
./target/debug/personhog-test-harness gate \
--leaders 3 --partitions 8 --persons 100 --concurrency 10 --duration 18s \
@@ -590,8 +582,6 @@ jobs:
--writer-crash-after 9s --restart-after 12s
- name: Run the e2e gate under chaos (coordinator failover + mid-handoff kill)
- env:
- RUST_BACKTRACE: 1
run: |
./target/debug/personhog-test-harness gate \
--routers 2 --leaders 3 --partitions 8 --persons 100 --concurrency 10 \
diff --git a/rust/personhog-test-harness/README.md b/rust/personhog-test-harness/README.md
index 57419c5cfc87..7c869a15fdef 100644
--- a/rust/personhog-test-harness/README.md
+++ b/rust/personhog-test-harness/README.md
@@ -34,7 +34,7 @@ target/debug/personhog-test-harness gate --external-router-url http://127.0.0.1:
--pg-target-table personhog_person_tmp
```
-The spawned stack is isolated from the dev stack: its own port range (51xxx), its own etcd prefix (`/personhog-test-harness/`), and a per-run changelog topic (`personhog_test_harness_<run_id>`, deleted on teardown).
+The spawned stack is isolated from the dev stack: its own port range (24xxx, kept below the ephemeral range so outbound connections cannot steal a listen port), its own etcd prefix (`/personhog-test-harness/`), and a per-run changelog topic (`personhog_test_harness_<run_id>`, deleted on teardown).
Persons are seeded directly in Postgres for a reserved harness team id (SQL is the interim seeding mechanism until the create RPC's future is settled; `src/seed.rs` is the swap seam).
Service logs land in `<bin-dir>/harness-logs/<run_id>/`.
diff --git a/rust/personhog-test-harness/src/stack/mod.rs b/rust/personhog-test-harness/src/stack/mod.rs
index 48cddbd35b91..a87a630a595b 100644
--- a/rust/personhog-test-harness/src/stack/mod.rs
+++ b/rust/personhog-test-harness/src/stack/mod.rs
@@ -17,13 +17,20 @@ use process::ServiceProcess;
/// dev stack (gRPC 50051-50054, metrics 9100-9105) without collisions.
/// Routers occupy base..base+3 and leaders start at base+6, which caps the
/// router count at 4.
-const REPLICA_GRPC_PORT: u16 = 51051;
-const ROUTER_GRPC_BASE_PORT: u16 = 51054;
-const LEADER_GRPC_BASE_PORT: u16 = 51060;
-const REPLICA_METRICS_PORT: u16 = 51151;
-const WRITER_METRICS_PORT: u16 = 51153;
-const ROUTER_METRICS_BASE_PORT: u16 = 51154;
-const LEADER_METRICS_BASE_PORT: u16 = 51160;
+///
+/// The range must stay below 32768: Linux allocates the local port of
+/// every outbound connection from the ephemeral range (default
+/// 32768-60999), so a fixed listen port inside it loses a lottery against
+/// whichever process's Kafka/PG/etcd connection grabbed the port first —
+/// during bring-up, every service opens outbound sockets in the same
+/// instant the listeners bind.
+const REPLICA_GRPC_PORT: u16 = 24051;
+const ROUTER_GRPC_BASE_PORT: u16 = 24054;
+const LEADER_GRPC_BASE_PORT: u16 = 24060;
+const REPLICA_METRICS_PORT: u16 = 24151;
+const WRITER_METRICS_PORT: u16 = 24153;
+const ROUTER_METRICS_BASE_PORT: u16 = 24154;
+const LEADER_METRICS_BASE_PORT: u16 = 24160;
const MAX_ROUTERS: u32 = 4;
const ETCD_PREFIX: &str = "/personhog-test-harness/";
diff --git a/rust/personhog-test-harness/src/stack/process.rs b/rust/personhog-test-harness/src/stack/process.rs
index b452ce3051d9..0c0412067c9f 100644
--- a/rust/personhog-test-harness/src/stack/process.rs
+++ b/rust/personhog-test-harness/src/stack/process.rs
@@ -31,7 +31,10 @@ impl ServiceSpec {
// PATH and HOME survive so the binaries can resolve tools and
// dotfiles (librdkafka, DNS, etc.) the way they do in dev.
.envs(env::vars().filter(|(k, _)| k == "PATH" || k == "HOME"))
- .env("RUST_BACKTRACE", "1")
+ // No RUST_BACKTRACE and no colors: a service panic's message is
+ // the signal, and fifty frames of runtime internals push it out
+ // of the log tail that failure reports embed.
+ .env("NO_COLOR", "1")
.env("RUST_LOG", "info")
.stdout(Stdio::from(log_file))
.stderr(Stdio::from(stderr_file))
@@ -174,6 +177,44 @@ impl ServiceProcess {
};
let all: Vec<&str> = content.lines().collect();
let start = all.len().saturating_sub(lines);
- all[start..].join("\n")
+ strip_ansi(&all[start..].join("\n"))
+ }
+}
+
+/// Strip ANSI escape sequences. Failure reports embed log tails inside the
+/// harness's own log output, where raw escapes render as `\x1b[2m` soup;
+/// spawned services get NO_COLOR but this guards logs written by anything
+/// that ignores it.
+fn strip_ansi(input: &str) -> String {
+ let mut out = String::with_capacity(input.len());
+ let mut chars = input.chars().peekable();
+ while let Some(c) = chars.next() {
+ if c != '\x1b' {
+ out.push(c);
+ continue;
+ }
+ // CSI sequences (ESC '[' ... final byte in @..~) are all tracing
+ // emits; a bare ESC before anything else just gets dropped.
+ if chars.peek() == Some(&'[') {
+ chars.next();
+ for c in chars.by_ref() {
+ if ('\x40'..='\x7e').contains(&c) {
+ break;
+ }
+ }
+ }
+ }
+ out
+}
+
+#[cfg(test)]
+mod tests {
+ use super::strip_ansi;
+
+ #[test]
+ fn strip_ansi_removes_csi_sequences_and_keeps_text() {
+ let colored = "\x1b[2m2026-07-15\x1b[0m \x1b[32m INFO\x1b[0m plain \x1b[3mkey\x1b[0m\x1b[2m=\x1b[0mvalue";
+ assert_eq!(strip_ansi(colored), "2026-07-15 INFO plain key=value");
+ assert_eq!(strip_ansi("no escapes"), "no escapes");
}
}