Skip to content

Commit 65abcfa

Browse files
committed
remove unneded shadow, add buffer and comment
1 parent c4fa012 commit 65abcfa

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

codersdk/workspaceagents.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,11 @@ func (c *Client) DialWorkspaceAgent(dialCtx context.Context, agentID uuid.UUID,
317317
return nil, xerrors.Errorf("parse url: %w", err)
318318
}
319319
closedCoordinator := make(chan struct{})
320-
firstCoordinator := make(chan error)
320+
// Must only ever be used once, send error OR close to avoid
321+
// reassignment race. Buffered so we don't hang in goroutine.
322+
firstCoordinator := make(chan error, 1)
321323
go func() {
322324
defer close(closedCoordinator)
323-
firstCoordinator := firstCoordinator // Shadowed so it can be reassigned outside goroutine.
324325
isFirst := true
325326
for retrier := retry.New(50*time.Millisecond, 10*time.Second); retrier.Wait(ctx); {
326327
options.Logger.Debug(ctx, "connecting")
@@ -370,10 +371,11 @@ func (c *Client) DialWorkspaceAgent(dialCtx context.Context, agentID uuid.UUID,
370371
return nil, xerrors.Errorf("parse url: %w", err)
371372
}
372373
closedDerpMap := make(chan struct{})
373-
firstDerpMap := make(chan error)
374+
// Must only ever be used once, send error OR close to avoid
375+
// reassignment race. Buffered so we don't hang in goroutine.
376+
firstDerpMap := make(chan error, 1)
374377
go func() {
375378
defer close(closedDerpMap)
376-
firstDerpMap := firstDerpMap // Shadowed so it can be reassigned outside goroutine.
377379
isFirst := true
378380
for retrier := retry.New(50*time.Millisecond, 10*time.Second); retrier.Wait(ctx); {
379381
options.Logger.Debug(ctx, "connecting to server for derp map updates")

0 commit comments

Comments
 (0)