github-vet / github-vet/rangeloop-pointer-findings
yjq-owner/bk-cmdb: src/source_controller/coreservice/core/model/attribute.go; 38 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [yjq-owner/bk-cmdb](https://www.github.com/yjq-owner/bk-cmdb) at [src/source_controller/coreservice/core/model/attribute.go](https://github.com/yjq-owner/bk-cmdb/blob/011400903fb92cf1c444ea32a6196ae4c457ee37/src/source_controller/coreservice/core/model/attribute.go#L139-L176)
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.
> function call which takes a reference to attr at line 143 may start a goroutine
[Click here to see the code in its original context.](https://github.com/yjq-owner/bk-cmdb/blob/011400903fb92cf1c444ea32a6196ae4c457ee37/src/source_controller/coreservice/core/model/attribute.go#L139-L176)
Click here to show the 38 line(s) of Go which triggered the analyzer.
```go
for attrIdx, attr := range inputParam.Attributes {
existsAttr, exists, err := m.isExists(ctx, attr.ObjectID, attr.PropertyID, attr.Metadata)
if nil != err {
addExceptionFunc(int64(attrIdx), err.(errors.CCErrorCoder), &attr)
continue
}
attr.OwnerID = ctx.SupplierAccount
if exists {
cond := mongo.NewCondition()
cond.Element(&mongo.Eq{Key: metadata.AttributeFieldSupplierAccount, Val: ctx.SupplierAccount})
cond.Element(&mongo.Eq{Key: metadata.AttributeFieldID, Val: existsAttr.ID})
_, err := m.update(ctx, mapstr.NewFromStruct(attr, "field"), cond)
if nil != err {
blog.Errorf("SetModelAttributes failed, failed to update the attribute(%#v) by the condition(%#v), err: %s, rid: %s", attr, cond.ToMapStr(), err.Error(), ctx.ReqID)
addExceptionFunc(int64(attrIdx), err.(errors.CCErrorCoder), &attr)
continue
}
dataResult.Updated = append(dataResult.Updated, metadata.UpdatedDataResult{
OriginIndex: int64(attrIdx),
ID: uint64(existsAttr.ID),
})
continue
}
id, err := m.save(ctx, attr)
if nil != err {
blog.Errorf("SetModelAttributes failed, failed to save the attribute(%#v), err: %s, rid: %s", attr, err.Error(), ctx.ReqID)
addExceptionFunc(int64(attrIdx), err.(errors.CCErrorCoder), &attr)
continue
}
dataResult.Created = append(dataResult.Created, metadata.CreatedDataResult{
OriginIndex: int64(attrIdx),
ID: id,
})
}
```
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: 011400903fb92cf1c444ea32a6196ae4c457ee37
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.