Skip to content

test(ci): #299/#300 deep diagnosis — fail-fast DB timeouts + live pg snapshot + graceful-teardown gate - #302

Merged
voidvec merged 5 commits into
masterfrom
fix/ci-299-300-investigation
Nov 3, 2026
Merged

voidvec merged 5 commits into
masterfrom
fix/ci-299-300-investigation

Conversation

@voidvec

@voidvec voidvec commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Purpose

Deep-dive + fix for #299 (one rotating login null-resp per full-suite run) and #300 (teardown use-after-free behind the fast-exit). Both root causes captured with hard evidence; the #299 flake is fixed.

#299 — root cause chain (all hypotheses tested against captured evidence)

Working method: fail-fast DB settings + an out-of-pool pg_stat_activity snapshot fired at the exact failure moment (tests/common/DbDiagnostics.h), steady-clock timestamps on every silent failure path, plus a local WSL CI-parity repro lab (2-CPU taskset, threads=4, fresh DB per run, pre-applied migrations).

Refuted by evidence (each was the leading theory at some point):

  • DB lock window: at the failure moment all 10 pool connections are server-side idle, zero locks, zero transactions (xact_age NULL everywhere).
  • Idle-in-transaction leftovers / migration DDL: same snapshot rules it out; the poller never saw one.
  • Pool-queue starvation as the primary cause: superseded (see below) — though drogon timeout:-1 (unbounded client-side sqlCmdBuffer_) is what converts any stall into an infinite null-resp.

Captured root cause (thread stacks via gdb attach mid-wedge + socket state + kernel counters):

  • The wedge is 61s of total server silence, always between two adjacent login_success audit inserts, self-healing afterwards. 61s = the test client's own 2×30s HTTP timeouts + retries.
  • Mid-wedge: every server event loop parked in epoll_wait (fully idle), DB fully caught up, client thread blocked in sendRequest's futex — and ss shows 4 CLOSE-WAIT + ~1800 TIME_WAIT with all kernel drop/overflow counters at zero.
  • Interpretation: the server sporadically accepts a TCP connection and never services it (CLOSE-WAIT = FIN received, app never watching). The per-request client strategy (~1800 fresh loopback connections per run) made the suite roll that dice ~1800×/run — CI hit it essentially every run, in whatever test the lost accept landed (the rotation).

Fix (test-side, this PR): a round-robin pool of 8 keep-alive HttpClients replaces per-request clients — ~200× smaller fresh-accept surface, no TIME_WAIT churn, no serialization (the old single-shared-client experiment serialized the suite ~5×). Companion: discardTestHttpClient() — drogon's timeout path keeps a possibly-dark connection (only the connect-error path resets it), so any transport failure swaps the slot for a fresh client.

Validation: 12/12 clean local full-suite runs (previously ~⅓ wedged; suite also ~2× faster), and this PR's CI legs — including the linux leg that failed with the flake on the diagnostics-only commit and the ASan full-suite leg — are all green.

Residual (filed separately): the server-side accept-but-never-service bug itself lives in drogon/trantor territory; with the pool, exposure is gone but the underlying behavior is tracked in a follow-up issue with the captured evidence.

#300 — teardown UAF pinned (diagnostics only; fast-exit stays)

FULLA_TEST_GRACEFUL_TEARDOWN=1 takes the graceful quit+join+return path on purpose. Under ASan+UBSan it reproduced deterministically at the static-destructor phase:

~HttpAppFrameworkImpl → ~SessionManager → ~CacheMap
  → CallbackEntry::~CallbackEntry() { cb_(); }        // drogon runs pending callbacks at destruction
  → SessionManager.cc:125 lambda's LOG_TRACE
  → trantor::Logger output fn → already-freed AsyncFileLogger  (UBSan: misaligned mutex @ 0x66266)

The fast-exit remains correct (it skips __run_exit_handlers entirely). Paste-ready upstream report: deliverables/drogon-upstream-issue-300-teardown-uaf.md (local) — needs a token with public-repo issue scope to file.

Also in this PR

  • Runtime test-config injection (test binary only): lock_timeout=3s, idle_in_transaction_session_timeout=60s, drogon SQL timeout=30 — the last one converts any future pool/queue stall into an attributable 500 instead of an infinite null.
  • Every silent nullopt path in loginAsUserTokensOnce / loginTokenVerbose now prints status+body+t+ms (the CI tail cluster previously hid which path bit).

Test plan

voidvec and others added 3 commits November 2, 2026 12:17
- #299 fail-fast: runtime test config injects lock_timeout=3s,
  idle_in_transaction_session_timeout=60s (connect_options) and drogon
  sql-timeout=30s; drogon timeout=-1 made the client-side sqlCmdBuffer_
  a time-unbounded queue (null-resp signature), and infinite lock waits
  stacked silently behind statement_timeout.
- #299 evidence: DbDiagnostics.h out-of-pool pg_stat_activity /
  pg_blocking_pids / ungranted-locks snapshot at the exact double-null
  moment (sendWithRetry hook) + steady-clock timestamps on every login
  diagnostic print; every silent nullopt path in loginAsUserTokensOnce /
  loginTokenVerbose now prints status+body.
- #300: FULLA_TEST_GRACEFUL_TEARDOWN=1 env gate takes the graceful
  quit+join path (the one that segfaults instrumented builds) so an ASan
  run can capture the UAF stack.
Luca added 2 commits November 2, 2026 18:18
…lients

Per-request clients opened ~1800 fresh loopback connections per suite
run; the captured wedge evidence shows the server sporadically accepts
a connection and never services it (CLOSE-WAIT + epoll-idle loops +
zero kernel drops), burning 2x30s HTTP timeouts = the ~61s null-resp
outage. A pool kills the churn without the 5x serialization of the
single-shared-client experiment.
@voidvec
voidvec marked this pull request as ready for review November 3, 2026 01:08
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-11-03T01:08:36.515786Z
We couldn’t complete this review. Comment @codex review to try again.
3ebe0a7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant