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

server: make clientConn() thread-safe #49073

Merged
merged 2 commits into from
Dec 2, 2023

Conversation

bb7133
Copy link
Member

@bb7133 bb7133 commented Nov 30, 2023

What problem does this PR solve?

Issue Number: ref #48224, #36793 and #32110

Problem Summary:

What changed and how does it work?

Please check #36793 (comment) for more details and context:

But for further enhancement, we cloud still try to make closeConn thread-safe.

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

  • None

Documentation

  • None

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 do-not-merge/needs-triage-completed 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 Nov 30, 2023
@bb7133 bb7133 changed the title server: make clientConn() thread-safe server: make clientConn() thread-safe Nov 30, 2023
Copy link

codecov bot commented Nov 30, 2023

Codecov Report

Merging #49073 (ccdc31d) into master (b21bb3e) will increase coverage by 1.0411%.
The diff coverage is 72.2222%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49073        +/-   ##
================================================
+ Coverage   71.0454%   72.0865%   +1.0411%     
================================================
  Files          1368       1405        +37     
  Lines        402993     413291     +10298     
================================================
+ Hits         286308     297927     +11619     
+ Misses        96744      96554       -190     
+ Partials      19941      18810      -1131     
Flag Coverage Δ
integration 43.6153% <72.2222%> (?)
unit 71.0443% <ø> (-0.0011%) ⬇️

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

Components Coverage Δ
dumpling 53.9663% <ø> (ø)
parser ∅ <ø> (∅)
br 48.3507% <ø> (-4.6207%) ⬇️

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. do-not-merge/needs-triage-completed and removed do-not-merge/needs-triage-completed labels Nov 30, 2023
@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 1, 2023
@@ -349,9 +350,13 @@ func (cc *clientConn) Close() error {
return closeConn(cc, connections)
}

// closeConn should be idempotent.
// closeConn is idempotent and thread-safe.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to ensure that concurrent invocations of closeConn are blocked until the first closeConn is finished? like sync.Once. I'm not sure if the second caller see closeConn is finished it will access other objects and will race with the running closeConn

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point! I'll update the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

PTAL @lance6716 , and I found that my previous implementation is explicitly noted as 'the incorrect one' in the comment of sync.Once

Copy link

ti-chi-bot bot commented Dec 2, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: lance6716, tiancaiamao

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [lance6716,tiancaiamao]

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

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 2, 2023
Copy link

ti-chi-bot bot commented Dec 2, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-01 03:01:35.598639478 +0000 UTC m=+1150924.263865664: ☑️ agreed by tiancaiamao.
  • 2023-12-02 02:06:22.13663193 +0000 UTC m=+1234010.801858126: ☑️ agreed by lance6716.

@ti-chi-bot ti-chi-bot bot merged commit 4382579 into pingcap:master Dec 2, 2023
16 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #49104.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Dec 2, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #49105.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Dec 2, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.1: #49106.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Dec 2, 2023
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Dec 4, 2023
ti-chi-bot bot pushed a commit that referenced this pull request Dec 6, 2023
@bb7133 bb7133 deleted the bb7133/safe_close branch December 12, 2023 18:26
@YangKeao
Copy link
Member

This PR also fix #42761 👍

@jackysp jackysp added the needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. label Jan 5, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #50107.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 5, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. 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.

6 participants