Skip to content

maintainer: avoid racy field access in schedule test#4298

Open
3AceShowHand wants to merge 1 commit intopingcap:masterfrom
3AceShowHand:codex/fix-maintainer-schedule-test-race
Open

maintainer: avoid racy field access in schedule test#4298
3AceShowHand wants to merge 1 commit intopingcap:masterfrom
3AceShowHand:codex/fix-maintainer-schedule-test-race

Conversation

@3AceShowHand
Copy link
Collaborator

@3AceShowHand 3AceShowHand commented Feb 27, 2026

What problem does this PR solve?

Issue Number: close #4297

TestMaintainerSchedule reads maintainer.postBootstrapMsg from the test goroutine while the maintainer event loop writes it, which causes race-detector flakes.

What is changed and how it works?

  • Replace the Eventually check to avoid reading non-atomic internal field directly.
  • Use maintainer.initialized.Load() together with maintainer.ddlSpan.IsWorking().

Tests

  • go test -race ./maintainer -run '^TestMaintainerSchedule$' -count=50

Release note

`None`

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 27, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a race condition within the TestMaintainerSchedule test. The issue stemmed from the test goroutine directly accessing a non-atomic internal field (postBootstrapMsg) while it was being concurrently modified by the maintainer's event loop. The fix involves updating the test's Eventually assertion to safely check the initialized status using an atomic load operation, thereby eliminating the flaky race condition and improving test reliability.

Highlights

  • Race Condition Fix: Addressed a race condition in TestMaintainerSchedule where the test goroutine was reading maintainer.postBootstrapMsg concurrently with the maintainer event loop writing to it, causing test flakes.
  • Test Assertion Update: Modified the Eventually check in the test to use maintainer.initialized.Load() in conjunction with maintainer.ddlSpan.IsWorking(), replacing direct access to a non-atomic internal field.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • maintainer/maintainer_test.go
    • Updated the require.Eventually condition to use maintainer.initialized.Load() instead of maintainer.postBootstrapMsg == nil to prevent a race condition.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@ti-chi-bot ti-chi-bot bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 27, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

A test condition was updated to use an atomic flag (initialized) instead of reading a non-atomic field (postBootstrapMsg), eliminating a data race condition while preserving the same logical test behavior.

Changes

Cohort / File(s) Summary
Test Concurrency Fix
maintainer/maintainer_test.go
Replaced unsafe read of postBootstrapMsg with thread-safe atomic initialized flag check to prevent data race in test assertion.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related issues

Poem

A rabbit hops through code so fair,
Where races once were lurking there,
With atoms bold and flags so bright,
The test now reads what's safe and right!
🐰✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: fixing racy field access in the maintainer schedule test by replacing a non-atomic field check with thread-safe alternatives.
Description check ✅ Passed The PR description includes all required sections with clear problem statement and solution details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a race condition in TestMaintainerSchedule. The change replaces a racy read of an internal field with a thread-safe atomic load to check for initialization. This not only resolves the data race but also makes the test logic more robust by waiting for the bootstrap process to complete. The implementation is correct.

@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Feb 27, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a data race in TestMaintainerSchedule that was detected by the race detector. The test was reading the non-atomic postBootstrapMsg field from the test goroutine while the maintainer event loop was writing to it concurrently, causing race-detector flakes.

Changes:

  • Replace racy field access postBootstrapMsg == nil with atomic field access initialized.Load() in the test's Eventually check
  • Add explanatory comment about avoiding non-atomic field access from test goroutine

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 27, 2026
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 27, 2026
@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 27, 2026

[LGTM Timeline notifier]

Timeline:

  • 2026-02-27 10:20:14.827389543 +0000 UTC m=+5038.746555611: ☑️ agreed by lidezhu.
  • 2026-02-27 12:39:27.435542529 +0000 UTC m=+13391.354708620: ☑️ agreed by tenfyzhong.

@ti-chi-bot
Copy link

ti-chi-bot bot commented Feb 27, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hongyunyan, lidezhu, tenfyzhong

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

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [hongyunyan,lidezhu,tenfyzhong]

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

@3AceShowHand
Copy link
Collaborator Author

/test all

3 similar comments
@3AceShowHand
Copy link
Collaborator Author

/test all

@3AceShowHand
Copy link
Collaborator Author

/test all

@3AceShowHand
Copy link
Collaborator Author

/test all

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

Labels

approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flaky test: data race in TestMaintainerSchedule on postBootstrapMsg

5 participants