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

session: handle nil store for plugins #37321

Merged
merged 2 commits into from
Aug 23, 2022
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
12 changes: 10 additions & 2 deletions session/tidb.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ type domainMap struct {
}

func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
key := store.UUID()

dm.mu.Lock()
defer dm.mu.Unlock()

if store == nil {
for _, d := range dm.domains {
// return available domain if any
return d, nil
}
return nil, errors.New("can not find available domain for a nil store")
}

key := store.UUID()

d = dm.domains[key]
if d != nil {
return
Expand Down
8 changes: 8 additions & 0 deletions session/tidb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import (
"github.com/stretchr/testify/require"
)

func TestDomapHandleNil(t *testing.T) {
// this is required for enterprise plugins
// ref: https://github.com/pingcap/tidb/issues/37319
require.NotPanics(t, func() {
_, _ = domap.Get(nil)
})
}

func TestSysSessionPoolGoroutineLeak(t *testing.T) {
store, dom := createStoreAndBootstrap(t)
defer func() { require.NoError(t, store.Close()) }()
Expand Down