github-vet / github-vet/rangeloop-pointer-findings
YuanDdQiao/dbtool: mongorsync-1.1/mongorsync/metadata.go; 53 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [YuanDdQiao/dbtool](https://www.github.com/YuanDdQiao/dbtool) at [mongorsync-1.1/mongorsync/metadata.go](https://github.com/YuanDdQiao/dbtool/blob/76b85e327e3426221be7ae311c8c1984c6fd399c/mongorsync-1.1/mongorsync/metadata.go#L371-L423)
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 arg used in defer or goroutine at line 412
[Click here to see the code in its original context.](https://github.com/YuanDdQiao/dbtool/blob/76b85e327e3426221be7ae311c8c1984c6fd399c/mongorsync-1.1/mongorsync/metadata.go#L371-L423)
Click here to show the 53 line(s) of Go which triggered the analyzer.
```go
for _, arg := range args {
/* if arg.intent.Size == 0 {
// MongoDB complains if we try and remove a non-existent collection, so we should
// just skip auth collections with empty .bson files to avoid gnarly logic later on.
log.Logf(log.Always, "%v file '%v' is empty; skipping %v restoration", arg.intentType, arg.intent.Location, arg.intentType)
}*/
// log.Logf(log.Always, "rsyncing %v from %v", arg.intentType, arg.intent.Location)
mergeArgs = append(mergeArgs, bson.DocElem{arg.mergeParamName, "admin." + arg.tempCollectionName})
/* err := arg.intent.BSONFile.Open()
if err != nil {
return err
}
defer arg.intent.BSONFile.Close()
bsonSource := db.NewDecodedBSONSource(db.NewBSONSource(arg.intent.BSONFile))
defer bsonSource.Close()
*/
tempCollectionNameExists, err := rsync.CollectionExists(&intents.Intent{DB: "admin", C: arg.tempCollectionName})
if err != nil {
return err
}
if tempCollectionNameExists {
log.Logf(log.Info, "dropping preexisting temporary collection admin.%v", arg.tempCollectionName)
err = session.DB("admin").C(arg.tempCollectionName).DropCollection()
if err != nil {
return fmt.Errorf("error dropping preexisting temporary collection %v: %v", arg.tempCollectionName, err)
}
}
log.Logf(log.DebugLow, "syncing %v to temporary collection", arg.intentType)
// if _, err = rsync.RsyncCollectionToDB("admin", arg.tempCollectionName, 0); err != nil {
if _, err = rsync.RsyncCollectionToDB("admin", arg.tempCollectionName, roles); err != nil {
return fmt.Errorf("error syncing %v: %v", arg.intentType, err)
}
// make sure we always drop the temporary collection
defer func() {
session, e := rsync.SessionProvider.GetSession()
if e != nil {
// logging errors here because this has no way of returning that doesn't mask other errors
log.Logf(log.Info, "error establishing connection to drop temporary collection admin.%v: %v", arg.tempCollectionName, e)
return
}
defer session.Close()
log.Logf(log.DebugHigh, "dropping temporary collection admin.%v", arg.tempCollectionName)
e = session.DB("admin").C(arg.tempCollectionName).DropCollection()
if e != nil {
log.Logf(log.Info, "error dropping temporary collection admin.%v: %v", arg.tempCollectionName, e)
}
}()
userTargetDB = arg.intent.DB
}
```
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: 76b85e327e3426221be7ae311c8c1984c6fd399c
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.