Skip to content

Commit

Permalink
cherry pick pingcap#37321 to release-6.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <[email protected]>
  • Loading branch information
xhebox authored and ti-srebot committed Aug 23, 2022
1 parent 1f7e2ce commit 77fdf88
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 @@ -49,11 +49,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 77fdf88

Please sign in to comment.