mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix data race in GetWebAssets (#90939)
This commit is contained in:
committed by
GitHub
parent
0a870e6a88
commit
95000f9fc8
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/api/dtos"
|
"github.com/grafana/grafana/pkg/api/dtos"
|
||||||
"github.com/grafana/grafana/pkg/services/licensing"
|
"github.com/grafana/grafana/pkg/services/licensing"
|
||||||
@@ -31,12 +32,21 @@ type EntryPointInfo struct {
|
|||||||
} `json:"assets,omitempty"`
|
} `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) {
|
func GetWebAssets(ctx context.Context, cfg *setting.Cfg, license licensing.Licensing) (*dtos.EntryPointAssets, error) {
|
||||||
if cfg.Env != setting.Dev && entryPointAssetsCache != nil {
|
entryPointAssetsCacheMu.RLock()
|
||||||
return entryPointAssetsCache, nil
|
ret := entryPointAssetsCache
|
||||||
|
entryPointAssetsCacheMu.RUnlock()
|
||||||
|
|
||||||
|
if cfg.Env != setting.Dev && ret != nil {
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
entryPointAssetsCacheMu.Lock()
|
||||||
|
defer entryPointAssetsCacheMu.Unlock()
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var result *dtos.EntryPointAssets
|
var result *dtos.EntryPointAssets
|
||||||
|
|||||||
Reference in New Issue
Block a user