Skip to content

fix(build): require Go 1.27.1 to avoid database/sql deadlocks - #29692

Merged
XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:codex/29673-go-sql-deadlock
Oct 8, 2026
Merged

XuPeng-SH merged 1 commit into
matrixorigin:mainfrom
XuPeng-SH:codex/29673-go-sql-deadlock

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

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

Which issue(s) this PR fixes:

Addresses the Go standard-library deadlock observed in #29673 CI. Upstream fix: golang/go#81043, backported in Go 1.27.1 through golang/go#81151.

What this PR does / why we need it:

Go 1.27.0's database/sql.closingMutex can lose a wakeup during concurrent Rows reading and closing, leaving both Rows.Err and the context-driven close permanently blocked. The failed pagination test in #29673 has matching stacks. The same fault reproduces with an unmodified official Go 1.27.0 toolchain and the upstream public Rows API reproducer, independently of MatrixOne. The exact original CI interleaving is inferred from its stacks.

Require Go 1.27.1 in go.mod so builds and tests consume the upstream synchronization fix, and synchronize the existing build prerequisites. Existing CI reads its Go version from go.mod; existing container builds automatically select a sufficient toolchain or fail explicitly when automatic selection is disabled. Published native/base image tags remain unchanged. No application locking, SQL assertions, dependencies, or test timeouts change.

This has no additional MatrixOne query-path overhead. Older build launchers may download a toolchain and miss compiler caches. Existing binaries must be rebuilt. Incorporate this patch into #29673 before rerunning its CI.

Validation on Linux amd64, Go 1.27.1:

  • Upstream public Rows API reproduction: official Go 1.27.0 wedges; Go 1.27.1 normal and race runs, and the Go 1.26.4 control, complete the bounded progress check. This diagnostic is not a performance benchmark or proof against unrelated deadlocks.
  • go1.27.0+auto selects Go 1.27.1; an explicit Go 1.27.0 local toolchain rejects the module. Read-only module loading leaves dependencies and go.sum unchanged.
  • Existing complete TestIssue25408PreparedPaginationParameters: normal PASS (24.047s); CI mode -short -tags matrixone_test -race PASS (32.098s), including the original stuck subcase.
  • make build PASS; generated mo-service -version loads and identifies Go 1.27.1.
  • Full make static-check-analysis PASS with the repository-pinned molint and golangci-lint 2.14.0, built using Go 1.27.1; 0 issues.
  • Diff check and all five documented minimum-version mentions PASS.
  • Design and overall review: explicit gpt-6.1-sol / xhigh; no delegated agents.

Remote PR CI remains pending at submission.

@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 →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deep review — no blocking findings / technically approvable

Reviewed head 0b993bf2e60614554ba57682b110199493447731 against base dce60631f8c857ae730a4d2f328df5962e4f2a8d. No subagents and no source modifications. This is a submitted COMMENT, not a GitHub APPROVE: the authenticated account is also the PR author.

Design and complete change map

  • Implementation: go.mod changes only the minimum toolchain patch version. The synchronization owner is Go's database/sql, so consuming its released fix is preferable to adding MatrixOne locks, retries, a second cleanup path, or changing assertions/timeouts. Module requirements/replacements and go.sum are unchanged.
  • Tests: zero test-source delta. The primitive-level regression belongs upstream; MatrixOne already has the integration test that exposed the failure. Reusing those tests is appropriate here; adding a timing-dependent copy to MatrixOne would add maintenance without an independent behavioral oracle.
  • Documentation: BUILD.md, INSTALLATION.md and README.md synchronize the five minimum-version mentions; BUILD.md links the upstream reason. Total diff is four files, +7/-6, with no process-history design document or compatibility branch.

Verified the original upstream defect, 1.27 backport, and the released Go 1.27.1 source, not just the PR description. The invalid transition is: writer reads 0 → reader acquires → writer acquisition CAS fails → last reader leaves without notification → writer uses stale 0 to set state 1 and sleeps with no owner left to wake it. The new acquire-or-retry branch for states 0/1 prevents that transition. Setting the waiting bit now requires an actual reader state, while the mutex around notification/parking preserves the wakeup handshake. Reader reentrancy/priority and cleanup ownership are not replaced.

QA and validation

Independent local checks used actual toolchains on Darwin/arm64 and a bounded, in-memory-driver public Rows probe adapted from the upstream reproducer. The probe also checks query completion and joins cleanup on successful shutdown.

Toolchain / scenario Observed result
Go 1.27.0, iteration vs explicit Close Stalled after 316 completed queries; reader and closer parked on the same closingMutex
Go 1.27.0, iteration vs context cancellation Stalled after 115,520 completed queries; writer was the standard library's own Rows.awaitDone → close
Go 1.27.1, explicit Close and context cancellation, normal and race All four 8-second bounded runs made progress and joined shutdown
Go 1.26.4 control, explicit Close Bounded progress and joined shutdown
Go 1.27.1 database/sql package, normal / race PASS, 0.364s / 1.604s
Go 1.27.1 TestClosingMutexLockRLockRace, race ×100 PASS, 3.273s; measured single test 0.02s, count capped at 100 under the 30-second adaptive budget
Old launcher, GOTOOLCHAIN=local / go1.27.0+auto Local rejects this module; auto selects 1.27.1
Diff check and isolated checkout PASS / clean

These probes demonstrate the defect and bounded progress after the fix; they are not performance benchmarks or proof against unrelated deadlocks.

Reused the exact-head completed CI run, rather than rerunning the entire MatrixOne suite. UT logs identify Go 1.27.1 and show the complete TestIssue25408PreparedPaginationParameters passing in 14.27s, including the originally stuck SQL_PREPARE_ABS_preserves_numeric_peer_provenance/scientific_fractional_float_peer subcase (0.07s). The test is in pkg/tests/issues, whose CI command uses -short -tags matrixone_test -race. SCA, shared build, UT/coverage, proxy BVT, pessimistic multi-CN BVT and CI Required all passed. Shared-build logs also identify Go 1.27.1 and this commit. Skipped checks are not counted as passes.

Unhappy-path audit

Rule Reviewed dependency / ownership Conclusion
Q1: effective cleanup owner Rows close/context watcher/connection return remain owned by database/sql; successful probe shutdown joins the active operations No new cleanup owner or duplicate lifecycle path
Q2: waits terminate Reader/closer → closingMutex → last-reader or writer notification Confirmed upstream lost-wakeup transition is eliminated; source analysis, old-version failures, new-version controls and race regression agree
Q3: growth is bounded This diff adds no queue, retained collection, goroutine or retry store No newly introduced accumulation mechanism

Performance, compatibility, delivery, and comments

There is no added MatrixOne query-path lock, allocation, storage format or execution branch. The upstream fix retries a failed acquisition instead of entering the invalid wait; I am not claiming a workload-wide speedup or zero regressions from every toolchain change. Existing reader-priority starvation behavior and unrelated driver-I/O blocking are outside this fix.

I traced standard, CI, dev and BVT build consumers. The Go 1.27.0 image tags are launcher/native-cache versions, not a bypass of the module minimum: the relevant root-module builds load go.mod and select a sufficient toolchain, or reject an explicitly pinned older one. Auto-download/cache cold-start cost and offline provisioning of Go ≥1.27.1 remain deployment requirements. Existing binaries must be rebuilt; this PR does not retrofit external prebuilt clients. There is no MatrixOne persisted-data format change, and no mixed-version-upgrade requirement was imposed.

Review/thread pagination is complete: there were no existing human review findings or review threads to resolve, only the paused-review bot notice. The exact interleaving of the original #29673 CI failure remains inferred from its matching stacks, as the PR correctly says; the defect itself and both close paths were independently reproduced here.

Conclusion: appropriately scoped fix at the existing owner, with sufficient positive/negative and integration evidence. No request-changes item found.

This branch was previously deployed

1 inactive deployment
ci — 0b993bf2 Deployed Oct 8, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/test-ci size/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

database/sql: closingMutex lost wakeup deadlocks Rows.Next against concurrent Rows.Close

2 participants