Skip to content

fix(coderd/provisionerdserver): pass through api ctx to provisionerdserver #10259

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 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
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
fix(coderd): pass server ctx into provisionerd server
  • Loading branch information
johnstcn committed Oct 16, 2023
commit ac5a8d356689d6560401b372b9717f3f1389982c
1 change: 1 addition & 0 deletions coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ func (api *API) CreateInMemoryProvisionerDaemon(ctx context.Context) (client pro
logger := api.Logger.Named(fmt.Sprintf("inmem-provisionerd-%s", name))
logger.Info(ctx, "starting in-memory provisioner daemon")
srv, err := provisionerdserver.NewServer(
ctx,
api.AccessURL,
uuid.New(),
logger,
Expand Down
33 changes: 21 additions & 12 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Options struct {
}

type server struct {
ctx context.Context
AccessURL *url.URL
ID uuid.UUID
Logger slog.Logger
Expand Down Expand Up @@ -107,6 +108,7 @@ func (t Tags) Valid() error {
}

func NewServer(
ctx context.Context,
accessURL *url.URL,
id uuid.UUID,
logger slog.Logger,
Expand All @@ -125,6 +127,9 @@ func NewServer(
options Options,
) (proto.DRPCProvisionerDaemonServer, error) {
// Panic early if pointers are nil
if ctx == nil {
return nil, xerrors.New("ctx is nil")
}
if quotaCommitter == nil {
return nil, xerrors.New("quotaCommitter is nil")
}
Expand Down Expand Up @@ -153,6 +158,7 @@ func NewServer(
options.AcquireJobLongPollDur = DefaultAcquireJobLongPollDur
}
return &server{
ctx: ctx,
AccessURL: accessURL,
ID: id,
Logger: logger,
Expand Down Expand Up @@ -1184,21 +1190,24 @@ func (s *server) CompleteJob(ctx context.Context, completed *proto.CompletedJob)
}
go func() {
for _, wait := range updates {
// Wait for the next potential timeout to occur. Note that we
// can't listen on the context here because we will hang around
// after this function has returned. The s also doesn't
// have a shutdown signal we can listen to.
<-wait
if err := s.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspaceBuild.WorkspaceID), []byte{}); err != nil {
// If the publish failed due to the context being canceled, there's nothing more for us
// to do here.
if errors.Is(err, context.Canceled) {
return
}
s.Logger.Error(context.Background(), "workspace notification after agent timeout failed",
select {
case <-s.ctx.Done():
// If the server is shutting down, we don't want to wait around.
s.Logger.Warn(context.Background(), "stopping notifications due to server shutdown",
slog.F("workspace_build_id", workspaceBuild.ID),
slog.Error(err),
)
case <-wait:
// Wait for the next potential timeout to occur. Note that we
// can't listen on the context here because we will hang around
// after this function has returned. The s also doesn't
// have a shutdown signal we can listen to.
if err := s.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspaceBuild.WorkspaceID), []byte{}); err != nil {
s.Logger.Error(context.Background(), "workspace notification after agent timeout failed",
slog.F("workspace_build_id", workspaceBuild.ID),
slog.Error(err),
)
}
}
}
}()
Expand Down
1 change: 1 addition & 0 deletions coderd/provisionerdserver/provisionerdserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ func setup(t *testing.T, ignoreLogErrors bool, ov *overrides) (proto.DRPCProvisi
}

srv, err := provisionerdserver.NewServer(
ctx,
&url.URL{},
srvID,
slogtest.Make(t, &slogtest.Options{IgnoreErrors: ignoreLogErrors}),
Expand Down
1 change: 1 addition & 0 deletions enterprise/coderd/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func (api *API) provisionerDaemonServe(rw http.ResponseWriter, r *http.Request)
logger := api.Logger.Named(fmt.Sprintf("ext-provisionerd-%s", name))
logger.Info(ctx, "starting external provisioner daemon")
srv, err := provisionerdserver.NewServer(
api.ctx,
api.AccessURL,
uuid.New(),
logger,
Expand Down