Skip to content

session,executor: scope finishStmt failpoint to current connection (#67655)#70016

Open
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-67655-to-release-8.5
Open

session,executor: scope finishStmt failpoint to current connection (#67655)#70016
ti-chi-bot wants to merge 1 commit into
pingcap:release-8.5from
ti-chi-bot:cherry-pick-67655-to-release-8.5

Conversation

@ti-chi-bot

@ti-chi-bot ti-chi-bot commented Jul 24, 2026

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #67655

What problem does this PR solve?

Issue Number: close #66728

Problem Summary:

TestFinishStmtError enables finishStmtError as a global failpoint, so unrelated sessions can also hit it while the test is running. That broad scope can destabilize this case and make flaky reports noisy.

What changed and how does it work?

  • scope finishStmtError to the current connection when the failpoint value is a numeric connection ID
  • update TestFinishStmtError to enable the failpoint with its own session connection ID
  • use t.Cleanup for disable and skip when the failpoint hook is inactive in the current test binary

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Summary by CodeRabbit

  • Tests

    • Improved test isolation for statement completion error scenarios.
    • Error simulation now targets the intended session, reducing interference between concurrent test connections.
    • Added safer cleanup and handling when the test condition cannot be enabled.
  • Bug Fixes

    • Improved reliability of session-specific error handling during statement completion.

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR. labels Jul 24, 2026
@ti-chi-bot

Copy link
Copy Markdown
Member Author

@zanmato1984 This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot ti-chi-bot Bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jul 24, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mjonss for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The finishStmtError failpoint is now scoped to a session connection ID. TestFinishStmtError enables the failpoint for its active connection, skips when unavailable, and uses cleanup-based disabling.

Changes

Finish statement failpoint scoping

Layer / File(s) Summary
Scope finishStmt error injection
pkg/session/tidb.go
The failpoint reads supported numeric values and returns the finish-statement error only when the value matches the session connection ID.
Update integration test setup
pkg/executor/staticrecordset/integration_test.go
The test formats a connection-specific failpoint expression, skips when enabling fails, and disables the failpoint through t.Cleanup.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • pingcap/tidb#68481: Both changes modify finishStmt error-path behavior and connection-related control flow.

Suggested labels: type/bug, approved, lgtm

Poem

A bunny scoped the failpoint just right,
One connection hops into sight.
The test cleans up with care,
No flaky tricks remain there—
Fresh green builds by morning light!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: scoping finishStmt failpoint handling to the current connection.
Description check ✅ Passed The description follows the template well, includes the required issue number, problem summary, changes, checklist, and release note.
Linked Issues check ✅ Passed The changes address #66728 by preventing unrelated sessions from triggering TestFinishStmtError's failpoint.
Out of Scope Changes check ✅ Passed The code changes stay focused on the failpoint scoping fix and the related test update, with no obvious unrelated edits.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/session/tidb.go`:
- Around line 247-272: Resolve the conflict in the finish-statement flow by
removing all Git conflict markers and retaining both behaviors: compute readOnly
once with sql.IsReadOnly(sessVars), run the existing connection-alive check when
applicable, and preserve the finishStmtError failpoint scoped to
sessVars.ConnectionID. Use the computed readOnly value for the subsequent
non-read-only branch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b36be74-ad24-4520-8984-dbabb9dd82be

📥 Commits

Reviewing files that changed from the base of the PR and between 10431d8 and 159d48a.

📒 Files selected for processing (2)
  • pkg/executor/staticrecordset/integration_test.go
  • pkg/session/tidb.go

Comment thread pkg/session/tidb.go
Comment on lines +247 to +272
<<<<<<< HEAD
readOnly := sql.IsReadOnly(sessVars)
if !readOnly && meetsErr == nil && shouldCheckConnectionAliveBeforeCommit(sessVars, sql) {
sessVars.SQLKiller.CheckConnectionAlive()
meetsErr = sessVars.SQLKiller.HandleSignal()
}
if !readOnly {
=======
failpoint.Inject("finishStmtError", func(val failpoint.Value) {
failCurrentSession := true
switch v := val.(type) {
case int:
failCurrentSession = uint64(v) == sessVars.ConnectionID
case int64:
failCurrentSession = uint64(v) == sessVars.ConnectionID
case uint64:
failCurrentSession = v == sessVars.ConnectionID
case float64:
failCurrentSession = uint64(v) == sessVars.ConnectionID
}
if failCurrentSession {
failpoint.Return(errors.New("occur an error after finishStmt"))
}
})
if !sql.IsReadOnly(sessVars) {
>>>>>>> 74a77b9dd8e (session,executor: scope finishStmt failpoint to current connection (#67655))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Resolve the cherry-pick conflict before merging.

The Git conflict markers remain in the Go source, so pkg/session/tidb.go cannot compile. Resolve this hunk by retaining both the connection-alive check and the connection-scoped failpoint, computing readOnly once, and using it for the later branch; selecting either side wholesale drops part of the intended behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/session/tidb.go` around lines 247 - 272, Resolve the conflict in the
finish-statement flow by removing all Git conflict markers and retaining both
behaviors: compute readOnly once with sql.IsReadOnly(sessVars), run the existing
connection-alive check when applicable, and preserve the finishStmtError
failpoint scoped to sessVars.ConnectionID. Use the computed readOnly value for
the subsequent non-read-only branch.

@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown

@ti-chi-bot: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
idc-jenkins-ci-tidb/check_dev_2 159d48a link true /test check-dev2
idc-jenkins-ci-tidb/check_dev 159d48a link true /test check-dev
idc-jenkins-ci-tidb/unit-test 159d48a link true /test unit-test
idc-jenkins-ci-tidb/mysql-test 159d48a link true /test mysql-test
idc-jenkins-ci-tidb/build 159d48a link true /test build

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

cherry-pick-approved Cherry pick PR approved by release team. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-8.5 This PR is cherry-picked to release-8.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants