Skip to content
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