mirror of https://github.com/grafana/grafana.git
fix data race in GetWebAssets (#90939)
This commit is contained in:
parent
0a870e6a88
commit
95000f9fc8
|
|
@ -8,6 +8,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/services/licensing"
|
||||
|
|
@ -31,12 +32,21 @@ type EntryPointInfo struct {
|
|||
} `json:"assets,omitempty"`
|
||||
}
|
||||
|
||||
var entryPointAssetsCache *dtos.EntryPointAssets = nil
|
||||
var (
|
||||
entryPointAssetsCacheMu sync.RWMutex // guard entryPointAssetsCache
|
||||
entryPointAssetsCache *dtos.EntryPointAssets // TODO: get rid of global state
|
||||
)
|
||||
|
||||
func GetWebAssets(ctx context.Context, cfg *setting.Cfg, license licensing.Licensing) (*dtos.EntryPointAssets, error) {
|
||||
if cfg.Env != setting.Dev && entryPointAssetsCache != nil {
|
||||
return entryPointAssetsCache, nil
|
||||
entryPointAssetsCacheMu.RLock()
|
||||
ret := entryPointAssetsCache
|
||||
entryPointAssetsCacheMu.RUnlock()
|
||||
|
||||
if cfg.Env != setting.Dev && ret != nil {
|
||||
return ret, nil
|
||||
}
|
||||
entryPointAssetsCacheMu.Lock()
|
||||
defer entryPointAssetsCacheMu.Unlock()
|
||||
|
||||
var err error
|
||||
var result *dtos.EntryPointAssets
|
||||
|
|
|
|||
Loading…
Reference in New Issue