mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
fix(enterprise/coderd): prevent deadlock during entitlements update (#8215)
This commit is contained in:
committed by
GitHub
parent
56395410bd
commit
31076ad665
@ -313,6 +313,7 @@ type API struct {
|
|||||||
// ProxyHealth checks the reachability of all workspace proxies.
|
// ProxyHealth checks the reachability of all workspace proxies.
|
||||||
ProxyHealth *proxyhealth.ProxyHealth
|
ProxyHealth *proxyhealth.ProxyHealth
|
||||||
|
|
||||||
|
entitlementsUpdateMu sync.Mutex
|
||||||
entitlementsMu sync.RWMutex
|
entitlementsMu sync.RWMutex
|
||||||
entitlements codersdk.Entitlements
|
entitlements codersdk.Entitlements
|
||||||
}
|
}
|
||||||
@ -329,8 +330,8 @@ func (api *API) Close() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *API) updateEntitlements(ctx context.Context) error {
|
func (api *API) updateEntitlements(ctx context.Context) error {
|
||||||
api.entitlementsMu.Lock()
|
api.entitlementsUpdateMu.Lock()
|
||||||
defer api.entitlementsMu.Unlock()
|
defer api.entitlementsUpdateMu.Unlock()
|
||||||
|
|
||||||
entitlements, err := license.Entitlements(
|
entitlements, err := license.Entitlements(
|
||||||
ctx, api.Database,
|
ctx, api.Database,
|
||||||
@ -457,6 +458,8 @@ func (api *API) updateEntitlements(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api.entitlementsMu.Lock()
|
||||||
|
defer api.entitlementsMu.Unlock()
|
||||||
api.entitlements = entitlements
|
api.entitlements = entitlements
|
||||||
api.AGPL.SiteHandler.Entitlements.Store(&entitlements)
|
api.AGPL.SiteHandler.Entitlements.Store(&entitlements)
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (api *API) shouldBlockNonBrowserConnections(rw http.ResponseWriter) bool {
|
func (api *API) shouldBlockNonBrowserConnections(rw http.ResponseWriter) bool {
|
||||||
api.entitlementsMu.Lock()
|
api.entitlementsMu.RLock()
|
||||||
browserOnly := api.entitlements.Features[codersdk.FeatureBrowserOnly].Enabled
|
browserOnly := api.entitlements.Features[codersdk.FeatureBrowserOnly].Enabled
|
||||||
api.entitlementsMu.Unlock()
|
api.entitlementsMu.RUnlock()
|
||||||
if browserOnly {
|
if browserOnly {
|
||||||
httpapi.Write(context.Background(), rw, http.StatusConflict, codersdk.Response{
|
httpapi.Write(context.Background(), rw, http.StatusConflict, codersdk.Response{
|
||||||
Message: "Non-browser connections are disabled for your deployment.",
|
Message: "Non-browser connections are disabled for your deployment.",
|
||||||
|
Reference in New Issue
Block a user