Skip to content

fix(enterprise/coderd): prevent deadlock during entitlements update #8215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ type API struct {
// ProxyHealth checks the reachability of all workspace proxies.
ProxyHealth *proxyhealth.ProxyHealth

entitlementsMu sync.RWMutex
entitlements codersdk.Entitlements
entitlementsUpdateMu sync.Mutex
entitlementsMu sync.RWMutex
entitlements codersdk.Entitlements
}

func (api *API) Close() error {
Expand All @@ -329,8 +330,8 @@ func (api *API) Close() error {
}

func (api *API) updateEntitlements(ctx context.Context) error {
api.entitlementsMu.Lock()
defer api.entitlementsMu.Unlock()
api.entitlementsUpdateMu.Lock()
defer api.entitlementsUpdateMu.Unlock()

entitlements, err := license.Entitlements(
ctx, api.Database,
Expand Down Expand Up @@ -457,6 +458,8 @@ func (api *API) updateEntitlements(ctx context.Context) error {
}
}

api.entitlementsMu.Lock()
defer api.entitlementsMu.Unlock()
api.entitlements = entitlements
api.AGPL.SiteHandler.Entitlements.Store(&entitlements)

Expand Down
4 changes: 2 additions & 2 deletions enterprise/coderd/workspaceagents.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
)

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