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

localbackend: fix resource leak when err on new local backend (#53664) #54618

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #53664

What problem does this PR solve?

Issue Number: close #53659

Problem Summary:

What changed and how does it work?

  • close them on error

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

i think it's too much to add so many failpoints to just test resource closed on err, so i write the test here

apply this diff to the code

diff --git a/pkg/lightning/backend/local/local.go b/pkg/lightning/backend/local/local.go
index f232d71d79..1d91833fa8 100644
--- a/pkg/lightning/backend/local/local.go
+++ b/pkg/lightning/backend/local/local.go
@@ -560,12 +560,14 @@ func NewBackend(
 		// the interface `ScatterRegions` may time out.
 		pd.WithCustomTimeoutOption(60*time.Second),
 	)
+	failpoint.InjectCall("failedToCreatePDClient", &err)
 	if err != nil {
 		return nil, common.NormalizeOrWrapErr(common.ErrCreatePDClient, err)
 	}
 
 	// The following copies tikv.NewTxnClient without creating yet another pdClient.
 	spkv, err = tikvclient.NewEtcdSafePointKV(strings.Split(config.PDAddr, ","), tls.TLSConfig())
+	failpoint.InjectCall("failedToCreateSafePointKV", &err)
 	if err != nil {
 		return nil, common.ErrCreateKVClient.Wrap(err).GenWithStackByArgs()
 	}
@@ -582,6 +584,7 @@ func NewBackend(
 	tikvCodec := pdCliForTiKV.GetCodec()
 	rpcCli = tikvclient.NewRPCClient(tikvclient.WithSecurity(tls.ToTiKVSecurityConfig()), tikvclient.WithCodec(tikvCodec))
 	tikvCli, err = tikvclient.NewKVStore("lightning-local-backend", pdCliForTiKV, spkv, rpcCli)
+	failpoint.InjectCall("failedToCreateKVStore", &err)
 	if err != nil {
 		return nil, common.ErrCreateKVClient.Wrap(err).GenWithStackByArgs()
 	}
@@ -594,6 +597,7 @@ func NewBackend(
 	importClientFactory = newImportClientFactoryImpl(splitCli, tls, config.MaxConnPerStore, config.ConnCompressType)
 
 	multiIngestSupported, err = checkMultiIngestSupport(ctx, pdCli, importClientFactory)
+	failpoint.InjectCall("failedToCheckMultiIngestSupport", &err)
 	if err != nil {
 		return nil, common.ErrCheckMultiIngest.Wrap(err).GenWithStackByArgs()
 	}

then in real-tikv-test which have routine leak check, add this:

func TestLocalBackendCleanOnErr(t *testing.T) {
	for _, fp := range []string{
		"failedToCreatePDClient",
		"failedToCreateSafePointKV",
		"failedToCreateKVStore",
		"failedToCheckMultiIngestSupport",
	} {
		t.Run(fp, func(t *testing.T) {
			fpName := "github.com/pingcap/tidb/pkg/lightning/backend/local/" + fp
			testfailpoint.EnableCall(t, fpName,
				func(errP *error) {
					*errP = fmt.Errorf("mock error" + fp)
				},
			)
			t.Cleanup(func() {
				require.NoError(t, failpoint.Disable(fpName))
			})
			_, err := local.NewBackend(context.Background(), &common.TLS{}, local.BackendConfig{
				PDAddr:                 "127.0.0.1:2379",
				RegionSplitBatchSize:   10,
				RegionSplitConcurrency: 1,
				MaxConnPerStore:        1,
				ConnCompressType:       config.CompressionNone,
			}, nil)
			require.ErrorContains(t, err, "mock error"+fp)
		})
	}
}
  • 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

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR. labels Jul 15, 2024
@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 16, 2024
@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 16, 2024
@D3Hunter
Copy link
Contributor

/test pull-lightning-integration-test

Copy link

ti-chi-bot bot commented Jul 16, 2024

@D3Hunter: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test pull-br-integration-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/release-7.5/ghpr_build
  • pingcap/tidb/release-7.5/ghpr_check
  • pingcap/tidb/release-7.5/ghpr_check2
  • pingcap/tidb/release-7.5/ghpr_mysql_test
  • pingcap/tidb/release-7.5/ghpr_unit_test

In response to this:

/test pull-lightning-integration-test

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/test-infra repository.

Copy link

tiprow bot commented Jul 16, 2024

@D3Hunter: No presubmit jobs available for pingcap/tidb@release-7.5

In response to this:

/test pull-lightning-integration-test

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.

@D3Hunter
Copy link
Contributor

/test ?

Copy link

ti-chi-bot bot commented Jul 16, 2024

@D3Hunter: The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test pull-br-integration-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/release-7.5/ghpr_build
  • pingcap/tidb/release-7.5/ghpr_check
  • pingcap/tidb/release-7.5/ghpr_check2
  • pingcap/tidb/release-7.5/ghpr_mysql_test
  • pingcap/tidb/release-7.5/ghpr_unit_test

In response to this:

/test ?

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/test-infra repository.

@D3Hunter
Copy link
Contributor

/test pull-br-integration-test

Copy link

tiprow bot commented Jul 16, 2024

@D3Hunter: No presubmit jobs available for pingcap/tidb@release-7.5

In response to this:

/test ?

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.

Copy link

tiprow bot commented Jul 16, 2024

@D3Hunter: No presubmit jobs available for pingcap/tidb@release-7.5

In response to this:

/test pull-br-integration-test

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.

Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 20.75472% with 42 lines in your changes missing coverage. Please review.

Please upload report for BASE (release-7.5@ed1e010). Learn more about missing BASE report.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-7.5     #54618   +/-   ##
================================================
  Coverage               ?   72.0167%           
================================================
  Files                  ?       1412           
  Lines                  ?     411349           
  Branches               ?          0           
================================================
  Hits                   ?     296240           
  Misses                 ?      95217           
  Partials               ?      19892           
Flag Coverage Δ
unit 72.0167% <20.7547%> (?)

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

Components Coverage Δ
dumpling 53.9913% <0.0000%> (?)
parser ∅ <0.0000%> (?)
br 53.4475% <0.0000%> (?)

@D3Hunter
Copy link
Contributor

/test pull-lightning-integration-test

Copy link

ti-chi-bot bot commented Jul 16, 2024

@D3Hunter: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test pull-br-integration-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/release-7.5/ghpr_build
  • pingcap/tidb/release-7.5/ghpr_check
  • pingcap/tidb/release-7.5/ghpr_check2
  • pingcap/tidb/release-7.5/ghpr_mysql_test
  • pingcap/tidb/release-7.5/ghpr_unit_test

In response to this:

/test pull-lightning-integration-test

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/test-infra repository.

Copy link

tiprow bot commented Jul 16, 2024

@D3Hunter: No presubmit jobs available for pingcap/tidb@release-7.5

In response to this:

/test pull-lightning-integration-test

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.

@D3Hunter
Copy link
Contributor

/test pull-lightning-integration-test

Copy link

ti-chi-bot bot commented Jul 16, 2024

@D3Hunter: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test build
  • /test check-dev
  • /test check-dev2
  • /test mysql-test
  • /test unit-test

The following commands are available to trigger optional jobs:

  • /test pull-br-integration-test

Use /test all to run the following jobs that were automatically triggered:

  • pingcap/tidb/release-7.5/ghpr_build
  • pingcap/tidb/release-7.5/ghpr_check
  • pingcap/tidb/release-7.5/ghpr_check2
  • pingcap/tidb/release-7.5/ghpr_mysql_test
  • pingcap/tidb/release-7.5/ghpr_unit_test

In response to this:

/test pull-lightning-integration-test

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/test-infra repository.

Copy link

tiprow bot commented Jul 16, 2024

@D3Hunter: No presubmit jobs available for pingcap/tidb@release-7.5

In response to this:

/test pull-lightning-integration-test

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.

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 16, 2024
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 16, 2024
Copy link

ti-chi-bot bot commented Jul 16, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-16 07:46:06.09544637 +0000 UTC m=+339988.086387841: ☑️ agreed by D3Hunter.
  • 2024-07-16 08:09:48.694738933 +0000 UTC m=+341410.685680402: ☑️ agreed by lance6716.

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jul 16, 2024
Copy link

ti-chi-bot bot commented Jul 16, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 3pointer, D3Hunter, lance6716

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:

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 the approved label Jul 16, 2024
@ti-chi-bot ti-chi-bot bot merged commit ac8777a into pingcap:release-7.5 Jul 16, 2024
37 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants