Skip to content

Commit

Permalink
session: handle nil store for plugins
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <[email protected]>
  • Loading branch information
xhebox committed Aug 23, 2022
1 parent 45588a1 commit 920b416
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 920b416

Please sign in to comment.