Skip to content

fix(conntrack): preserve connection lifecycle event order - #32854

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/conntrack-ordered-events-32851
Nov 17, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
LeftHandCold:fix/conntrack-ordered-events-32851

Conversation

@LeftHandCold

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32851

What this PR does / why we need it:

Use one ordered conntrack receiver, through the existing Listen API.
conntrack v0.5.1 workers independently receive, decode and publish events.
With multiple workers a flow's DESTROY can reach logConnTrack before its NEW,
even when every event was received. The consumer then retains the destroyed
flow and reports an incorrect active-connection count.

This is intentionally separate from the socket/watcher upgrade in #32845.
It does not change dependencies, the 65,536-event channel, the map consumer,
SQL behavior, or shutdown ownership. No expiry, tombstone map, reconciliation
loop or new configuration is introduced. The unused runtime import is removed.

The existing startup/Listen-failure test now captures the worker count and
requires one ordered listener, while retaining its socket-cleanup assertion.
This avoids creating an unowned Background monitor in the unit test.

Validation on 50

Base: 43addc16ba30c3e5a0feb11447078092a5fc3953 (Main).
Linux amd64, Go 1.27.1, GOAMD64=v3, GOEXPERIMENT=simd, GOWORK=off.

  • Regression red/green: the new startup assertion fails against original
    production code (got 20 workers); fixed code passes, including 100 race
    repetitions in one process.
  • Native artifacts rebuilt in the isolated worktree through make -j4 cgo.
  • Complete cmd/mo-service normal tests: 169 pass, zero skipped/failed.
  • Complete cmd/mo-service race tests: 169 pass, zero skipped/failed
    (24.039 seconds package execution).
  • Incremental SCA: repository-selected molint and golangci-lint 2.14.0 on the
    full affected package pass, zero reported issues; git diff --check passes.
  • Real kernel test in disposable network namespaces: eight producers create
    and delete 16,384 synthetic UDP flows per run. Validate exactly 16,384 NEW
    and 16,384 DESTROY events, matching flow IDs, no receive errors and an empty
    kernel table before checking the consumer's map rule.
Bounded kernel workload Original 20 workers, three runs Fixed 1 worker, three runs
32-flow batches: stale map entries 2990 / 2965 / 2904 0 / 0 / 0
64-flow batches: stale map entries 2636 / 2487 / 2648 0 / 0 / 0
  • Kernel race stress: 20 repetitions in one process, 327,680 complete flow
    lifecycles
    , all events received, kernel and map zero at every run's end;
    no race reports. Additional three-run race calibration also passes.
  • Compatibility control using fix(conntrack): avoid socket watchers for background receives #32845's socket v0.7.0 dependency graph:
    three 16,384-flow runs also pass with one worker and zero residual entries.

Capacity and scope boundary

The bounded normal tests observed roughly 90k–115k events/sec with the current
Main dependencies. This is a synthetic capacity check, not a production
throughput guarantee; concurrent compilation and batching affect timing.

Larger 256/2048-flow bursts hit the existing kernel receive-buffer limit in
both configurations
. Those failures are not counted as passing tests. The
dependency terminates a worker on fatal receive errors; single-worker listening
does not add loss recovery and must not be described as fixing all possible
conntrack inaccuracies. Kernel-loss reconciliation is outside this no-loss
event-order fix. No buffer sizes were changed to make the tests pass.

SQL BVT is not the changed boundary: this patch only changes Linux diagnostic
event delivery, verified with the real netlink interface. No customer/host
conntrack entries were changed. This does not claim to fix the separate
#31954 panic, reproduce an OOM, or address database correctness.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Queue requested — the merge queue status continues in this comment ↓.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 31a0362ffc223bcd519db9f37fa7d88b6dea992a

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 31a0362ffc223bcd519db9f37fa7d88b6dea992a

Assessment: approve

The single receiver preserves receive/decode/publication order through the existing conntrack owner, preventing the demonstrated no-loss map retention without adding state or recovery machinery. No actionable defect remains.

Model: gpt-6.1-sol / max

Session: 01a1e395-a6d9-7ad1-bf20-81f1c6210100 · slot 2 · generation 0

Validation:

  • Reviewed the complete delta and affected startup, consumer and close paths; verified pinned conntrack/netfilter/netlink source archives against frozen go.sum checksums.

  • Reused successful frozen-head build, UT, SCA, coverage and compose CI results, plus attributed author regression, owning-package normal/race and bounded kernel/churn/capacity reports.

  • Clean-source, scope, discussion and receipt/log audits passed; validation-reconciliation.json records the retained evidence.

Limitations:

  • No local Go/native/kernel tests were rerun. Author runtime/race/capacity reports lack raw local_validation artifacts; synthetic throughput is not a production guarantee.

  • Kernel event loss and fatal receive errors remain outside this no-loss ordering fix. The separate #31954 panic is not claimed resolved.

@mergify mergify Bot added the queued label Nov 17, 2026
@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request dequeued

3 h 35 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 10:13 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 13:48 · 37f9908

Reason

Pull request #32854 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

To get back in the queue

  • Push a change if one is needed: the pull request is queued again once its queue conditions match.
  • If no change is needed, tick the box below to queue it again as it is.

Merge conditions not met when it left the queue

  • any of · required by GitHub branch protection:
    • check-neutral = CI Required
    • check-skipped = CI Required
    • check-success = CI Required

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request
2 merge conditions met
  • #review-threads-unresolved = 0 · required by GitHub branch protection
  • github-review-approved · required by GitHub branch protection

Times in UTC · dashboard · how the merge queue works

@LeftHandCold

Copy link
Copy Markdown
Collaborator Author

已补上本轮挑战确认的 ENOBUFS 后监控永久停止问题:后续 PR #32865(本 PR 已合并,故没有改写原分支)。保留单 worker 顺序性,致命错误后关闭旧 listener、限频重建并使用独立的新统计;明确标记 since_listener_start / complete=false,不冒充丢失期间的完整内核快照。最终只改两个文件,不改 SQL、依赖或服务退出流程。全包 normal/race 各 186 项通过,8 个专项各 race 100 次通过;隔离 netns 中真实 ENOBUFS 恢复三轮通过,每轮后续 32 TCP + 32 UDP 的 NEW/DESTROY 都进入实际 MO 消费者并归零。增量 SCA、构建通过;新 PR 的 CI 尚待完成。

mergify Bot pushed a commit that referenced this pull request Nov 17, 2026
## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #32851. Follow-up to merged #32854 for the fatal-receive-error availability gap identified during its review.

## What this PR does / why we need it:

The ordered, single-worker conntrack listener exits on ENOBUFS or a decode error. Previously MO only logged that error and continued reporting its stale map forever. This affects diagnostic connection statistics, not SQL or stored data.

- Retain one worker and the existing 65,536-entry queue. A fatal listener error invalidates that statistics generation, closes its socket, and retries with fresh queues/map at most once every five seconds.
- Drain pending publications while joining the old listener. Stop retrying if socket cleanup itself fails; repeated Dial/Listen failures do not busy-loop or accumulate listeners.
- Keep existing log names/count fields, adding `scope=since_listener_start`, `complete=false`, and a start timestamp. This resumes future observation; it does **not** reconstruct events lost during overflow or claim a full kernel-table snapshot.
- Preserve optional startup and process lifetime. No SQL path, dependency, service-shutdown hook, configuration, periodic dump, or reconciliation framework changes.

Validation on Linux/Go 1.27.1, using the current socket v0.7.0 dependency:

- Full `cmd/mo-service` package: normal and race both pass, 186 tests/subtests, zero skipped.
- Eight focused lifecycle tests: 100 race repetitions each. Covers stale-generation isolation, repeated recovery, bounded failed retries, closed/nil channels, blocked publications, and cleanup failures.
- Actual changed MO consumer/supervisor in an isolated network namespace: three race-enabled rounds each force a real kernel ENOBUFS, restart, observe 32 TCP + 32 UDP flows and their deletion, and report `0 -> 64 -> 0`. Final kernel dump is empty; cleanup joins successfully.
- Incremental molint and golangci-lint 2.14.0: pass; native-linked binary build and `-h`: pass.

The monitor remains process-owned. An extra immediate-shutdown hook was deliberately excluded after testing exposed the dependency's worker-registration/Close race; runtime recovery here starts only after the worker has delivered its fatal error. Initial permission/setup failure remains nonfatal and does not start background retries. Repository-wide CI and production acceptance remain separate from these local results.


Approved-by: XuPeng-SH <[email protected]>

This branch was successfully deployed

No deployments
ci — 37f99081 Deployed Nov 17, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dequeued kind/bug Something isn't working size/S Denotes a PR that changes [10,99] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Concurrent conntrack event delivery retains destroyed flows in CN monitoring map

3 participants