github-vet / github-vet/rangeloop-pointer-findings
dewey363/vendor: github.com/youtube/vitess/go/vt/worker/legacy_split_clone.go; 56 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [dewey363/vendor](https://www.github.com/dewey363/vendor) at [github.com/youtube/vitess/go/vt/worker/legacy_split_clone.go](https://github.com/dewey363/vendor/blob/b3663f2caef453c40d7a7714012a5cb4e5f46cde/github.com/youtube/vitess/go/vt/worker/legacy_split_clone.go#L545-L600)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable shardIndex used in defer or goroutine at line 579
[Click here to see the code in its original context.](https://github.com/dewey363/vendor/blob/b3663f2caef453c40d7a7714012a5cb4e5f46cde/github.com/youtube/vitess/go/vt/worker/legacy_split_clone.go#L545-L600)
Click here to show the 56 line(s) of Go which triggered the analyzer.
```go
for shardIndex := range scw.sourceShards {
sema := sync2.NewSemaphore(scw.sourceReaderCount, 0)
for tableIndex, td := range sourceSchemaDefinition.TableDefinitions {
var keyResolver keyspaceIDResolver
if *useV3ReshardingMode {
keyResolver, err = newV3ResolverFromTableDefinition(keyspaceSchema, td)
if err != nil {
return fmt.Errorf("cannot resolve v3 sharding keys for keyspace %v: %v", scw.keyspace, err)
}
} else {
keyResolver, err = newV2Resolver(scw.keyspaceInfo, td)
if err != nil {
return fmt.Errorf("cannot resolve sharding keys for keyspace %v: %v", scw.keyspace, err)
}
}
rowSplitter := NewRowSplitter(scw.destinationShards, keyResolver)
chunks, err := generateChunks(ctx, scw.wr, scw.sourceTablets[shardIndex], td, scw.sourceReaderCount, defaultMinRowsPerChunk)
if err != nil {
return err
}
scw.tableStatusList.setThreadCount(tableIndex, len(chunks)-1)
for _, c := range chunks {
sourceWaitGroup.Add(1)
go func(td *tabletmanagerdatapb.TableDefinition, tableIndex int, chunk chunk) {
defer sourceWaitGroup.Done()
sema.Acquire()
defer sema.Release()
scw.tableStatusList.threadStarted(tableIndex)
// Start streaming from the source tablets.
tp := newSingleTabletProvider(ctx, scw.wr.TopoServer(), scw.sourceAliases[shardIndex])
rr, err := NewRestartableResultReader(ctx, scw.wr.Logger(), tp, td, chunk, false /* allowMultipleRetries */)
if err != nil {
processError("NewRestartableResultReader failed: %v", err)
return
}
defer rr.Close(ctx)
// process the data
dbNames := make([]string, len(scw.destinationShards))
for i, si := range scw.destinationShards {
keyspaceAndShard := topoproto.KeyspaceShardString(si.Keyspace(), si.ShardName())
dbNames[i] = scw.destinationDbNames[keyspaceAndShard]
}
if err := scw.processData(ctx, dbNames, td, tableIndex, rr, rowSplitter, insertChannels, scw.destinationPackCount); err != nil {
processError("processData failed: %v", err)
}
scw.tableStatusList.threadDone(tableIndex)
}(td, tableIndex, c)
}
}
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: b3663f2caef453c40d7a7714012a5cb4e5f46cde
Contributor guide
No contributing guide indexed for this repository
Research direction
Inspect github.com/youtube/vitess/go/vt/worker/legacy_split_clone.go around lines 545-600, especially the goroutine using shardIndex at line 579. Compare the analyzer finding with the surrounding loop and determine whether it is a Bug, Mitigated, or Desirable Behavior, then leave the corresponding reaction on the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100