Skip to content

Commit 0e568fb

Browse files
committed
fix copilot nits
1 parent a997f82 commit 0e568fb

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

agent/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,9 @@ func (a *agent) createTailnet(
14821482
if err = a.trackGoroutine(func() {
14831483
defer apiListener.Close()
14841484
apiHandler, closeAPIHAndler := a.apiHandler()
1485+
defer func() {
1486+
_ = closeAPIHAndler()
1487+
}()
14851488
server := &http.Server{
14861489
BaseContext: func(net.Listener) context.Context { return ctx },
14871490
Handler: apiHandler,

agent/agentcontainers/api.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ type API struct {
4545

4646
// lockCh protects the below fields. We use a channel instead of a
4747
// mutex so we can handle cancellation properly.
48-
lockCh chan struct{}
49-
containers codersdk.WorkspaceAgentListContainersResponse
50-
mtime time.Time
51-
devcontainerNames map[string]struct{} // Track devcontainer names to avoid duplicates.
52-
knownDevcontainers []codersdk.WorkspaceAgentDevcontainer // Track predefined and runtime-detected devcontainers.
53-
configModifiedTimes map[string]time.Time // Track when config files were last modified.
48+
lockCh chan struct{}
49+
containers codersdk.WorkspaceAgentListContainersResponse
50+
mtime time.Time
51+
devcontainerNames map[string]struct{} // Track devcontainer names to avoid duplicates.
52+
knownDevcontainers []codersdk.WorkspaceAgentDevcontainer // Track predefined and runtime-detected devcontainers.
53+
configFileModifiedTimes map[string]time.Time // Track when config files were last modified.
5454
}
5555

5656
// Option is a functional option for API.
@@ -108,16 +108,16 @@ func WithWatcher(w watcher.Watcher) Option {
108108
func NewAPI(logger slog.Logger, options ...Option) *API {
109109
ctx, cancel := context.WithCancel(context.Background())
110110
api := &API{
111-
ctx: ctx,
112-
cancel: cancel,
113-
done: make(chan struct{}),
114-
logger: logger,
115-
clock: quartz.NewReal(),
116-
cacheDuration: defaultGetContainersCacheDuration,
117-
lockCh: make(chan struct{}, 1),
118-
devcontainerNames: make(map[string]struct{}),
119-
knownDevcontainers: []codersdk.WorkspaceAgentDevcontainer{},
120-
configModifiedTimes: make(map[string]time.Time),
111+
ctx: ctx,
112+
cancel: cancel,
113+
done: make(chan struct{}),
114+
logger: logger,
115+
clock: quartz.NewReal(),
116+
cacheDuration: defaultGetContainersCacheDuration,
117+
lockCh: make(chan struct{}, 1),
118+
devcontainerNames: make(map[string]struct{}),
119+
knownDevcontainers: []codersdk.WorkspaceAgentDevcontainer{},
120+
configFileModifiedTimes: make(map[string]time.Time),
121121
}
122122
for _, opt := range options {
123123
opt(api)
@@ -281,7 +281,7 @@ func (api *API) getContainers(ctx context.Context) (codersdk.WorkspaceAgentListC
281281
// Check if this container was created after the config
282282
// file was modified.
283283
if configFile != "" && api.knownDevcontainers[knownIndex].Dirty {
284-
lastModified, hasModTime := api.configModifiedTimes[configFile]
284+
lastModified, hasModTime := api.configFileModifiedTimes[configFile]
285285
if hasModTime && container.CreatedAt.After(lastModified) {
286286
api.logger.Info(ctx, "clearing dirty flag for container created after config modification",
287287
slog.F("container", container.ID),
@@ -316,7 +316,7 @@ func (api *API) getContainers(ctx context.Context) (codersdk.WorkspaceAgentListC
316316

317317
dirty := dirtyStates[workspaceFolder]
318318
if dirty {
319-
lastModified, hasModTime := api.configModifiedTimes[configFile]
319+
lastModified, hasModTime := api.configFileModifiedTimes[configFile]
320320
if hasModTime && container.CreatedAt.After(lastModified) {
321321
api.logger.Info(ctx, "new container created after config modification, not marking as dirty",
322322
slog.F("container", container.ID),
@@ -473,7 +473,7 @@ func (api *API) markDevcontainerDirty(configPath string, modifiedAt time.Time) {
473473
}
474474

475475
// Record the timestamp of when this configuration file was modified.
476-
api.configModifiedTimes[configPath] = modifiedAt
476+
api.configFileModifiedTimes[configPath] = modifiedAt
477477

478478
for i := range api.knownDevcontainers {
479479
if api.knownDevcontainers[i].ConfigPath == configPath {

0 commit comments

Comments
 (0)