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

ricktian1226/BatteryRun: MazeServer2.0.0/gocode/src/guanghuan.com/xiaoyao/battery_transaction_server/business/xyapi_iapvalidate.go; 51 LoC

Open
#7,483 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 [ricktian1226/BatteryRun](https://www.github.com/ricktian1226/BatteryRun) at [MazeServer2.0.0/gocode/src/guanghuan.com/xiaoyao/battery_transaction_server/business/xyapi_iapvalidate.go](https://github.com/ricktian1226/BatteryRun/blob/c5176485339a69271b83a23982801a67b443c7c1/MazeServer2.0.0/gocode/src/guanghuan.com/xiaoyao/battery_transaction_server/business/xyapi_iapvalidate.go#L136-L186)

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 transaction at line 140 may start a goroutine

[Click here to see the code in its original context.](https://github.com/ricktian1226/BatteryRun/blob/c5176485339a69271b83a23982801a67b443c7c1/MazeServer2.0.0/gocode/src/guanghuan.com/xiaoyao/battery_transaction_server/business/xyapi_iapvalidate.go#L136-L186)

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

```go
for _, transaction := range iapTransactions {
transaction.Uid = proto.String(uid)
transaction.OpDate = proto.String(opDate)
transaction.Timestamp = proto.Int64(now)
xylog.Debug(uid, "transaction info : %v", &transaction)

//1.00.00以前的客户端,需要在对收据内的transaction遍历时进行防重放校验
tid := transaction.GetTransactionId()
if bOldStyle {
isExist, err = api.GetDB(xybusiness.BUSINESS_COLLECTION_INDEX_IAPTRANSACTION).IsTransactionExsit(tid)
if err != xyerror.ErrOK || err != xyerror.ErrNotFound {
subFailReason = xyerror.IAP_DB_ERROR
bKick = true
xylog.Error(uid, "verify receipt db error: %v", err)
} else if isExist {
subFailReason = xyerror.IAP_SUCCESS
bKick = true
xylog.Warning(uid, "verify receipt transactionid [%s] already exists in DB.iaptransaction", tid)
}

//如果交易被过滤掉了,添加到返回结果中
if bKick {
api.appendTransactionItem(tid, subFailReason, &(resp.Items))
continue
}
}

err = api.GetDB(xybusiness.BUSINESS_COLLECTION_INDEX_IAPTRANSACTION).AddIapTransaction(&transaction)
xylog.Debug(uid, "IapTransaction %v", &transaction)

// 查询购买的商品属性
moneygoods = xybusinesscache.DefGoodsCacheManager.IapGood(transaction.GetItemId())
if moneygoods == nil {
xylog.Error(uid, "[%s] [IapValidate] get iapgood(%s) info err: %v", uid, transaction.GetItemId(), err)
api.appendTransactionItem(transaction.GetTransactionId(), xyerror.IAP_INVALID_GOODS, &(resp.Items))
continue
}

// 扫尾工作:增加物品
xylog.Debug(uid, "add MoneyGoods %v", moneygoods)

//err = api.GainProps(uid, accountWithFlag, moneygoods.GetItems(), ACCOUNT_UPDATE_NO_DELAY, battery.MoneySubType_iap)
err = api.GainProps(uid, nil, moneygoods.GetItems(), ACCOUNT_UPDATE_NO_DELAY, battery.MoneySubType_iap)
if err == xyerror.ErrOK {
api.SendIapStatistic(uid, transaction.GetItemId(), tid)
}

//记录该条交易结果
api.appendTransactionItem(transaction.GetTransactionId(), xyerror.IAP_SUCCESS, &(resp.Items))
resp.GoodsList = append(resp.GoodsList, moneygoods.GetId())
}

```

Click here to show extra information the analyzer produced.

```
The following paths through the callgraph could lead to a goroutine:
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (connect, 0) -> (Match, 2)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (parse, 1) -> (GetFlags, 0) -> (closeConnection, 0) -> (reConnectToRoute, 1) -> (removeFromCache, 2)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (OpenDB, 0) -> (DBError, 1) -> (SetSocketTimeout, 1) -> (SetTimeout, 1) -> (Ping, 0)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (AppLogConfig, 2) -> (DebugNoId, 2) -> (DebugNoId, 2) -> (Split, 2)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (insertChunk, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (Start, 0) -> (QueueSubscribe, 3)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (New, 0) -> (Refresh, 0) -> (unsetSocket, 0) -> (Release, 0) -> (Connect, 1) -> (newSocket, 3)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (NewLogger, 2) -> (NewLogger, 1) -> (startLogger, 0) -> (WriteMsg, 2) -> (docheck, 1) -> (DoRotate, 0)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (NewLogger, 2) -> (NewLogger, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (New, 0) -> (Refresh, 0) -> (unsetSocket, 0) -> (Release, 0) -> (Read, 1) -> (getChunk, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (Start, 0) -> (QueueSubscribe, 3) -> (subscribe, 4)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (AppLogConfig, 2) -> (DebugNoId, 2) -> (DebugNoId, 2) -> (Split, 2) -> (Run, 0) -> (Shutdown, 0) -> (StoreUint32, 2)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (LoadConfig, 0) -> (LottoInit, 0) -> (ToString, 0) -> (DebugNoId, 3)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (parse, 1) -> (GetFlags, 0) -> (closeConnection, 0) -> (reConnectToRoute, 1) -> (connectToRoute, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (Start, 0) -> (QueueSubscribe, 3) -> (subscribe, 4) -> (isReconnecting, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (OpenDB, 0) -> (DBError, 1) -> (SetSocketTimeout, 1) -> (SetTimeout, 1) -> (Ping, 0) -> (SetSafe, 1) -> (ensureSafe, 1) -> (logf, 1) -> (newServer, 4)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (ReadYmlReader, 1) -> (Println, 3) -> (getChunk, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (Start, 0) -> (QueueSubscribe, 3) -> (subscribe, 4) -> (isReconnecting, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (OpenDB, 0) -> (DBError, 1) -> (SetSocketTimeout, 1) -> (SetTimeout, 1) -> (Ping, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (docheck, 1) -> (DoRotate, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (run, 0) -> (tarjanSort, 1) -> (idList, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (AcquireSocket, 2) -> (Connect, 1) -> (newSocket, 3)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (NewLogger, 2) -> (NewLogger, 1) -> (startLogger, 0) -> (WriteMsg, 2) -> (connect, 0) -> (Match, 2) -> (SubexpNames, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (Get, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (AddRouter, 3) -> (Head, 2) -> (addRoute, 3) -> (Validate, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (New, 0) -> (Refresh, 0) -> (unsetSocket, 0) -> (Release, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (AppLogConfig, 2) -> (DebugNoId, 2) -> (DebugNoId, 2) -> (Split, 2) -> (connectToNodes, 0) -> (forwardTapEvents, 3)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (run, 0) -> (tarjanSort, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (connect, 0) -> (Match, 2) -> (SubexpNames, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (OpenDB, 0) -> (DBError, 1) -> (SetSocketTimeout, 1) -> (SetTimeout, 1) -> (Ping, 0) -> (syncServersLoop, 0) -> (Empty, 0) -> (logf, 1) -> (newServer, 4)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (Start, 0) -> (QueueSubscribe, 3)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (Start, 0) -> (QueueSubscribe, 3) -> (subscribe, 4)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (Start, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (parse, 1) -> (GetFlags, 0) -> (closeConnection, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (parse, 1) -> (GetFlags, 0) -> (closeConnection, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (parse, 1) -> (GetFlags, 0) -> (closeConnection, 0) -> (reConnectToRoute, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (run, 0)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (AppLogConfig, 2) -> (DebugNoId, 2) -> (DebugNoId, 2) -> (Split, 2) -> (Run, 0)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (NewLogger, 2) -> (NewLogger, 1) -> (startLogger, 0) -> (WriteMsg, 2) -> (connect, 0) -> (Match, 2)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (LoadConfig, 0) -> (LottoInit, 0) -> (ToString, 0) -> (DebugNoId, 3)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (Start, 0) -> (QueueSubscribe, 3) -> (subscribe, 4) -> (isReconnecting, 0) -> (mcb, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (handleSignals, 0) -> (SendShutdownSignal, 0) -> (generateFmtStr, 1) -> (f, 3) -> (OpenDB, 0) -> (DBError, 1) -> (SetSocketTimeout, 1) -> (SetTimeout, 1) -> (Ping, 0) -> (syncServersLoop, 0) -> (Empty, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (New, 0) -> (Refresh, 0) -> (unsetSocket, 0)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (AppLogConfig, 2) -> (DebugNoId, 2) -> (DebugNoId, 2) -> (Split, 2) -> (Run, 0) -> (Shutdown, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (parse, 1) -> (GetFlags, 0) -> (closeConnection, 0) -> (reConnectToRoute, 1)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (New, 0) -> (Refresh, 0) -> (unsetSocket, 0) -> (Release, 0) -> (Write, 5) -> (WaitForPersistence, 3) -> (CheckPersistence, 2) -> (Observe, 2)
(Debug, 3) -> (Log, 3) -> (Trace, 2) -> (AddTimeIncrement, 1) -> (AppLogConfig, 2) -> (DebugNoId, 2) -> (DebugNoId, 2) -> (Split, 2) -> (connectToNodes, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (Start, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (AddRouter, 3) -> (Head, 2) -> (addRoute, 3) -> (Validate, 0)
(Debug, 3) -> (Log, 3) -> (Error, 2) -> (New, 1) -> (String, 0) -> (int32, 1) -> (UnixNano, 0) -> (token, 1) -> (OpenDB, 0) -> (DBError, 1) -> (SetSocketTimeout, 1) -> (SetTimeout, 1) -> (Ping, 0) -> (SetSafe, 1) -> (ensureSafe, 1)

```

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: c5176485339a69271b83a23982801a67b443c7c1

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.