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

executor: migrate goroutine leak tests to goleak #27405

Merged
merged 3 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (s *testPrepareSuite) TearDownSuite(c *C) {

func (s *baseTestSuite) TearDownSuite(c *C) {
s.domain.Close()
s.store.Close()
c.Assert(s.store.Close(), IsNil)
}

func (s *globalIndexSuite) SetUpSuite(c *C) {
Expand Down Expand Up @@ -8569,7 +8569,7 @@ func (s testSerialSuite) assertTemporaryTableNoNetwork(c *C, temporaryTableType
// With that failpoint, all requests to the TiKV is discard.
rs, err := tk1.Exec("select * from normal")
c.Assert(err, IsNil)
blocked := make(chan struct{})
blocked := make(chan struct{}, 1)
Copy link
Contributor Author

@tisonkun tisonkun Aug 19, 2021

Choose a reason for hiding this comment

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

It should be a buffer channel to unblock L8576, otherwise the anon goroutine blocked and leaks.

ctx, cancelFunc := context.WithCancel(context.Background())
go func() {
_, err := session.ResultSetToStringSlice(ctx, tk1.Se, rs)
Expand Down
9 changes: 7 additions & 2 deletions executor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
package executor

import (
"os"
"testing"

"github.com/pingcap/tidb/util/testbridge"
"go.uber.org/goleak"
)

func TestMain(m *testing.M) {
testbridge.WorkaroundGoCheckFlags()
os.Exit(m.Run())
opts := []goleak.Option{
goleak.IgnoreTopFunction("go.etcd.io/etcd/pkg/logutil.(*MergeLogger).outputLoop"),
goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"),
goleak.IgnoreTopFunction("gopkg.in/natefinch/lumberjack%2ev2.(*Logger).millRun"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

but still I don't know where this function comes from.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, outputLoop comes from the etcd client. I don't know where lumberjack is. You may try go mod graph.
`

Copy link
Contributor Author

@tisonkun tisonkun Aug 20, 2021

Choose a reason for hiding this comment

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

@xhebox I found it comes from pingcap/log

func initFileLog(cfg *FileLogConfig) (*lumberjack.Logger, error) {
  return &lumberjack.Logger
}

millRun seems like a daemon goroutine that range on millCh which is never closed.

func (l *Logger) millRun() {
	for _ = range l.millCh {
		// what am I going to do, log this?
		_ = l.millRunOnce()
	}
}

Copy link
Member

Choose a reason for hiding this comment

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

natefinch/lumberjack#56, It's a goroutine leak bug.

}
goleak.VerifyTestMain(m, opts...)
}
5 changes: 5 additions & 0 deletions executor/sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (s *testTableSampleSuite) SetUpSuite(c *C) {
s.domain = d
}

func (s *testTableSampleSuite) TearDownSuite(c *C) {
s.domain.Close()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

do not close domain and store generates 30+ goroutine leaks

c.Assert(s.store.Close(), IsNil)
}

func (s *testTableSampleSuite) initSampleTest(c *C) *testkit.TestKit {
atomic.StoreUint32(&ddl.EnableSplitTableRegion, 1)
tk := testkit.NewTestKit(c, s.store)
Expand Down
2 changes: 1 addition & 1 deletion executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *seqTestSuite) SetUpSuite(c *C) {

func (s *seqTestSuite) TearDownSuite(c *C) {
s.domain.Close()
s.store.Close()
c.Assert(s.store.Close(), IsNil)
}

func (s *seqTestSuite) TestEarlyClose(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion executor/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (s *testUpdateSuite) SetUpSuite(c *C) {

func (s *testUpdateSuite) TearDownSuite(c *C) {
s.domain.Close()
s.store.Close()
c.Assert(s.store.Close(), IsNil)
}

func (s *testUpdateSuite) TearDownTest(c *C) {
Expand Down