Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

owner: fix bug of owner manager hang #58622

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tiancaiamao
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #58620

Problem Summary:

What changed and how does it work?

The owner compaign loop use wrong ctx for refressSession, so owner.Close() may hang sometimes.

Before the fix, the behavior is:

ctx := context.Background()
m := NewOwnerManager(ctx, ...)
m.Close()  // no, this cannot make m exit

Call Close() may hang, unless we pass a ctx to NewOwnerManager and cancel that ctx:

ctx, cancel := context.WithCancel(context.Background())
m := NewOwnerManager(ctx, ...)
m.Close() // no, this cannot make m exit
cancel()  // ok, this can make m exit

This is not what I expected. Close() should not hang!

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot ti-chi-bot bot added 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. labels Dec 30, 2024
Copy link

ti-chi-bot bot commented Dec 30, 2024

[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 benjamin2037 for approval. For more information see the Code Review Process.

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

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

Copy link

tiprow bot commented Dec 30, 2024

Hi @tiancaiamao. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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.

@@ -364,13 +364,13 @@ func (m *ownerManager) campaignLoop(campaignContext context.Context) {
select {
case <-m.etcdSes.Done():
m.logger.Info("etcd session done, refresh it")
if err2 := m.refreshSession(util2.NewSessionRetryUnlimited, ManagerSessionTTL); err2 != nil {
if err2 := m.refreshSession(campaignContext, util2.NewSessionRetryUnlimited, ManagerSessionTTL); err2 != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the core of the fix.
We should pass the campaignContext.

The code is:

campaignContext, cancel := context.WithCancel(m.ctx)
go campaignLoop(campaignContext)
cancel()

If we use m.ctx in the campaign loop, cancel() cannot cancel the ctx!

ownerMgr.etcdSes.Close()

// This should not hang.
ownerMgr.Close()
Copy link
Contributor Author

@tiancaiamao tiancaiamao Dec 30, 2024

Choose a reason for hiding this comment

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

Without the fix, the test hang... because the old code use wrong ctx and cancel in owner manager Close() does make campaign loop break.

@tiancaiamao tiancaiamao requested a review from D3Hunter December 30, 2024 12:07
Copy link

ti-chi-bot bot commented Dec 30, 2024

@tiancaiamao: The following test 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/unit-test 83c610c link true /test unit-test

Full PR test history. Your PR dashboard.

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.

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

Attention: Patch coverage is 0% with 13 lines in your changes missing coverage. Please review.

Project coverage is 73.5190%. Comparing base (70393b5) to head (83c610c).
Report is 22 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #58622        +/-   ##
================================================
+ Coverage   73.1072%   73.5190%   +0.4117%     
================================================
  Files          1676       1676                
  Lines        463352     463975       +623     
================================================
+ Hits         338744     341110      +2366     
+ Misses       103774     102004      -1770     
- Partials      20834      20861        +27     
Flag Coverage Δ
integration 42.8645% <0.0000%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.6910% <ø> (ø)
parser ∅ <ø> (∅)
br 45.8233% <ø> (+0.0089%) ⬆️

Copy link
Contributor

@D3Hunter D3Hunter left a comment

Choose a reason for hiding this comment

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

not a bug, we purposed do that, see

tidb/pkg/owner/manager.go

Lines 439 to 444 in 42d4fae

// Note: we must use manager's context to create session. If we use campaign
// context and the context is cancelled, the created session cannot be closed
// as session close depends on the context.
// One drawback is that when you want to break the campaign loop, and the campaign
// loop is refreshing the session, it might wait for a long time to return, it
// should be fine as long as network is ok, and acceptable to wait when not.

it's ok to wait, except on shutdown where the context should be cancelled

@D3Hunter
Copy link
Contributor

/hold

@ti-chi-bot ti-chi-bot bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

owner manager hang in BreakCampaignLoop
2 participants