Skip to content

test(coderd): close metricscache and avoid background context #7996

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 6 commits into from
Jun 13, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Ensure closure on error
  • Loading branch information
mafredri committed Jun 13, 2023
commit 401ba7b7562fd287fdf27804efb43f6c9add9d3e
15 changes: 12 additions & 3 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
// New constructs an Enterprise coderd API instance.
// This handler is designed to wrap the AGPL Coder code and
// layer Enterprise functionality on top as much as possible.
func New(ctx context.Context, options *Options) (*API, error) {
func New(ctx context.Context, options *Options) (_ *API, err error) {
if options.EntitlementsUpdateInterval == 0 {
options.EntitlementsUpdateInterval = 10 * time.Minute
}
Expand All @@ -59,6 +59,11 @@ func New(ctx context.Context, options *Options) (*API, error) {
AGPL: coderd.New(options.Options),
Options: options,
}
defer func() {
if err != nil {
_ = api.Close()
}
}()

api.AGPL.Options.SetUserGroups = api.setUserGroups

Expand Down Expand Up @@ -312,8 +317,12 @@ type API struct {

func (api *API) Close() error {
api.cancel()
_ = api.replicaManager.Close()
_ = api.derpMesh.Close()
if api.replicaManager != nil {
_ = api.replicaManager.Close()
}
if api.derpMesh != nil {
_ = api.derpMesh.Close()
}
return api.AGPL.Close()
}

Expand Down