Skip to content

Commit 8292e1a

Browse files
e2bclaude
authored andcommitted
fix: remove unnecessary loop var capture (Go 1.22+)
Go 1.22+ changed loop variable semantics — each iteration gets its own copy. No need to capture deviceIndex/i before the goroutine. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1349e6a commit 8292e1a

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

packages/orchestrator/pkg/sandbox/nbd/path_direct.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,14 @@ func (d *DirectPathMount) Open(ctx context.Context) (retDeviceIndex uint32, err
119119
server.Close()
120120

121121
dispatch := NewDispatch(serverc, d.Backend)
122-
// Capture loop variables for the goroutine closure to avoid a data
123-
// race: deviceIndex is reassigned on each retry iteration of the
124-
// outer for-loop while the goroutine may still read it.
125-
devIdx := deviceIndex
126122
// Start reading commands on the socket and dispatching them to our provider
127123
d.handlersWg.Go(func() {
128124
handleErr := dispatch.Handle(ctx)
129125
// The error is expected to happen if the nbd (socket connection) is closed
130126
logger.L().Info(ctx, "closing handler for NBD commands",
131127
zap.Error(handleErr),
132-
zap.Uint32("device_index", devIdx),
133-
zap.Int("socket_index", sockIdx),
128+
zap.Uint32("device_index", deviceIndex),
129+
zap.Int("socket_index", i),
134130
)
135131
})
136132

0 commit comments

Comments
 (0)