Skip to content

fix(conntrack): avoid socket watchers for background receives - #32845

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/conntrack-socket-watcher-31954
Nov 17, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
LeftHandCold:fix/conntrack-socket-watcher-31954

Conversation

@LeftHandCold

@LeftHandCold LeftHandCold commented Nov 17, 2026 •

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:

Related to #31954. Keep the issue open for field acceptance; this removes the observed failing path but does not claim a deterministic reproduction of the negative WaitGroup counter.

Fixes #32848 (nested Iceberg adapter dependency/build drift).

What this PR does / why we need it:

The CN crash in #31954 occurs in socket v0.5.1's per-operation cancellation watcher beneath conntrack/netlink. Netlink receives with context.Background(), yet that version still creates a watcher and WaitGroup for every receive.

Upgrade github.com/mdlayher/socket to upstream v0.7.0:

  • A context with a nil Done channel no longer creates a cancellation watcher, removing that path from conntrack's Background receives.
  • Cancellable operations observe cancellation even with a distant deadline.
  • Watchers finish before resetting the socket deadline, avoiding a stale deadline affecting subsequent I/O.

Keep conntrack enabled and retain its existing ownership. No MO production lifecycle rewrite, recovery shim, SQL/storage change or dependency fork. The upgrade requires x/net v0.58.0 and its crypto/text/tools/mod module closure; netlink and conntrack versions remain unchanged.

Synchronize the independent Iceberg adapter module's dependency versions/checksums as well. Its local root-module replacement does not inherit root replace directives, so also mirror the existing usearch fork required by the native ABI. The missing usearch replacement reproduces on the clean PR base; this is not a socket runtime regression. No native or adapter production code changes are needed.

Add three privilege-free real-socket contracts beside the conntrack consumer: Background receipt, cancellation followed by socket reuse, and Close of 16 admitted receivers. The cancellation contract fails on v0.5.1 and passes on v0.7.0. It reproduces the cancellation defect, not the production negative-counter panic; inspection of the old code does not establish a double-Done cause.

Local validation on 50, against Main e1160015bb58, Go 1.27.1 with matching native artifacts:

  • Incremental golangci and pinned molint: passed; gofmt/diff checks and module tidy/verify clean.
  • Full cmd/mo-service UT and race: passed, 172 named tests/subtests each, no skips. Each new socket contract also passed 100 race repetitions.
  • socket/netlink/netfilter/conntrack race suites passed; two environment-dependent namespace tests skipped. Separately, real conntrack events and 16-worker Close passed under race in an isolated network namespace.
  • MO geo/function consumers of the required crypto/text changes passed. x/net http2/proxy/ipv6 passed. Two ipv4 multicast tests exceeded the shared host's membership limit but passed with a real multicast interface in an isolated namespace; no full isolated ipv4-suite pass is claimed.
  • Built and ran the modified MO binary with conntrack active. Existing transaction/Prepared/DDL BVT: 135/135 twice on the same instance, no skips; teardown checks clean. Conntrack event counts were nonzero, no receive watcher stacks remained, and shutdown exited 0 without OOM or panic.
  • Independent Iceberg module: tidy diff clean, readonly tagged package loading and module verification passed. Actual make test-iceberg-adapter passed in normal and race modes, 9/9 tests each, no skips. Earlier root/socket/BVT evidence is reused because this follow-up only changes the nested module metadata. Full Iceberg SQL/MinIO E2E is not claimed.

Long-duration and multi-CN field acceptance remain necessary. This is not a claim that every CN crash or the ultimate negative-counter cause has been resolved.

Review also identified the independent, pre-existing conntrack event-order/retention bug #32851 on both base and head. It is not fixed or closed by this dependency upgrade and should receive a separate ordered-event handling fix.

@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: 5688e567ca28bc4eac7ab91bcb5610e5ba12d7e9

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: 5688e567ca28bc4eac7ab91bcb5610e5ba12d7e9

Assessment: approve

No actionable defects found. The upgrade reuses upstream socket lifecycle handling and aligns the independent Iceberg module without adding MO runtime machinery.

Model: gpt-6.1-sol / max

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

Validation:

  • Go 1.27.1 focused socket tests passed: 3/3 normal, 3/3 race, then 100 race iterations per test; no skips or race reports.

  • The socket v0.5.1 control failed the cancellation test as expected; v0.7.0 passed.

  • Verified pinned dependency sources and checksums. Frozen-head CI reports successful build, UT, native, BVT and Iceberg module-tidy checks.

  • validation-audit.json matches claimed local checks to command/source/exit receipts and retained logs. Source remained clean; discussion-assessment.json covers all three discussion entries.

Limitations:

  • Local execution covered the socket test file. Full service/native/adapter suites were not rerun locally; broader evidence comprises frozen CI statuses and attributed author reports. Iceberg E2E was skipped.

  • The negative-WaitGroup panic cause remains unproven. Field acceptance in #31954 and the preexisting event-order issue #32851 remain separate.

@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 33 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Tue 17 Nov, 09:58 · rule main · triggered by rule Automatic queue on approval for main
  • ⏹️ Testing stopped · in place
  • 🚫 Left the queue 13:31 · e365ddc

Reason

Pull request #32845 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

@XuPeng-SH
XuPeng-SH merged commit 5294772 into matrixorigin:main Nov 17, 2026
@mergify mergify Bot added dequeued and removed queued labels Nov 17, 2026
XuPeng-SH 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:

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 #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.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was successfully deployed

No deployments
ci — e365ddc9 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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: PR #32845 leaves Iceberg adapter module stale, breaking its build and test target

3 participants