github-vet / github-vet/rangeloop-pointer-findings

yjq-owner/bk-cmdb: src/source_controller/coreservice/core/model/attribute.go; 51 LoC

Open
#6,231 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
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#L63-L113)

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 72 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#L63-L113)

Click here to show the 51 line(s) of Go which triggered the analyzer.

```go
for attrIdx, attr := range inputParam.Attributes {
// fmt.Sprintf("coreservice:create:model:%s:attr:%s", objID, attr.PropertyID)
redisKey := lock.GetLockKey(lock.CreateModuleAttrFormat, objID, attr.PropertyID)

locker := lock.NewLocker(m.cache)
looked, err := locker.Lock(redisKey, time.Second*35)
defer locker.Unlock()
if err != nil {
blog.ErrorJSON("create model error. get create look error. err:%s, input:%s, rid:%s", err.Error(), inputParam, ctx.ReqID)
addExceptionFunc(int64(attrIdx), ctx.Error.CCErrorf(common.CCErrCommRedisOPErr), &attr)
continue
}
if !looked {
blog.ErrorJSON("create model have same task in progress. input:%s, rid:%s", inputParam, ctx.ReqID)
addExceptionFunc(int64(attrIdx), ctx.Error.CCErrorf(common.CCErrCommOPInProgressErr, fmt.Sprintf("create object(%s) attribute(%s)", attr.ObjectID, attr.PropertyName)), &attr)
continue
}
if attr.IsPre {
if attr.PropertyID == common.BKInstNameField {
attr.PropertyName = util.FirstNotEmptyString(ctx.Lang.Language("common_property_"+attr.PropertyID), attr.PropertyName, attr.PropertyID)
}
}

attr.OwnerID = ctx.SupplierAccount
_, exists, err := m.isExists(ctx, attr.ObjectID, attr.PropertyID, attr.Metadata)
blog.V(5).Infof("CreateModelAttributes isExists info. property id:%s, metadata:%#v, exit:%v, rid:%s", attr.PropertyID, attr.Metadata, exists, ctx.ReqID)
if nil != err {
blog.Errorf("CreateModelAttributes failed, attribute field propertyID(%s) exists, err: %s, rid: %s", attr.PropertyID, err.Error(), ctx.ReqID)
addExceptionFunc(int64(attrIdx), err.(errors.CCErrorCoder), &attr)
continue
}

if exists {
dataResult.CreateManyInfoResult.Repeated = append(dataResult.CreateManyInfoResult.Repeated, metadata.RepeatedDataResult{
OriginIndex: int64(attrIdx),
Data: mapstr.NewFromStruct(attr, "field"),
})
continue
}
id, err := m.save(ctx, attr)
if nil != err {
blog.Errorf("CreateModelAttributes 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.CreateManyInfoResult.Created = append(dataResult.CreateManyInfoResult.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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.