Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 31076ad

Browse files
authored
fix(enterprise/coderd): prevent deadlock during entitlements update (#8215)
1 parent 5639541 commit 31076ad

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

enterprise/coderd/coderd.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ type API struct {
313313
// ProxyHealth checks the reachability of all workspace proxies.
314314
ProxyHealth *proxyhealth.ProxyHealth
315315

316-
entitlementsMu sync.RWMutex
317-
entitlements codersdk.Entitlements
316+
entitlementsUpdateMu sync.Mutex
317+
entitlementsMu sync.RWMutex
318+
entitlements codersdk.Entitlements
318319
}
319320

320321
func (api *API) Close() error {
@@ -329,8 +330,8 @@ func (api *API) Close() error {
329330
}
330331

331332
func (api *API) updateEntitlements(ctx context.Context) error {
332-
api.entitlementsMu.Lock()
333-
defer api.entitlementsMu.Unlock()
333+
api.entitlementsUpdateMu.Lock()
334+
defer api.entitlementsUpdateMu.Unlock()
334335

335336
entitlements, err := license.Entitlements(
336337
ctx, api.Database,
@@ -457,6 +458,8 @@ func (api *API) updateEntitlements(ctx context.Context) error {
457458
}
458459
}
459460

461+
api.entitlementsMu.Lock()
462+
defer api.entitlementsMu.Unlock()
460463
api.entitlements = entitlements
461464
api.AGPL.SiteHandler.Entitlements.Store(&entitlements)
462465

enterprise/coderd/workspaceagents.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import (
99
)
1010

1111
func (api *API) shouldBlockNonBrowserConnections(rw http.ResponseWriter) bool {
12-
api.entitlementsMu.Lock()
12+
api.entitlementsMu.RLock()
1313
browserOnly := api.entitlements.Features[codersdk.FeatureBrowserOnly].Enabled
14-
api.entitlementsMu.Unlock()
14+
api.entitlementsMu.RUnlock()
1515
if browserOnly {
1616
httpapi.Write(context.Background(), rw, http.StatusConflict, codersdk.Response{
1717
Message: "Non-browser connections are disabled for your deployment.",

0 commit comments

Comments
 (0)