diff --git a/session/tidb.go b/session/tidb.go index c7d93f71d7081..2e531b24e3adb 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -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 diff --git a/session/tidb_test.go b/session/tidb_test.go index 70831a8f64d89..e2808080b7c1c 100644 --- a/session/tidb_test.go +++ b/session/tidb_test.go @@ -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()) }()