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

couchbase/indexing: secondary/indexer/indexer.go; 106 LoC

Open
#9,857 0 comments 0 reactions 0 assignees View on GitHub
fresh large
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [couchbase/indexing](https://www.github.com/couchbase/indexing) at [secondary/indexer/indexer.go](https://github.com/couchbase/indexing/blob/c10c28f1e61017748dd0e6c083b2f887ca1faabc/secondary/indexer/indexer.go#L4367-L4472)

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 streamId used in defer or goroutine at line 4432

[Click here to see the code in its original context.](https://github.com/couchbase/indexing/blob/c10c28f1e61017748dd0e6c083b2f887ca1faabc/secondary/indexer/indexer.go#L4367-L4472)

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

```go
for _, streamId := range indexStreamIds {

respCh := make(MsgChannel)

if idx.getStreamKeyspaceIdState(streamId, keyspaceId) == STREAM_INACTIVE {
logging.Warnf("Indexer::removeIndexesFromStream Stream %v KeyspaceId %v "+
"KeyspaceId stream not active. Skipping.", streamId, keyspaceId)
continue
}

sessionId := idx.getCurrentSessionId(streamId, keyspaceId)
isRemoveKeyspace := false
if idx.checkKeyspaceIdExistsInStream(keyspaceId, streamId, false) {

cmd = &MsgStreamUpdate{mType: REMOVE_INDEX_LIST_FROM_STREAM,
streamId: streamId,
indexList: indexList,
respCh: respCh,
sessionId: sessionId,
}
} else {
cmd = &MsgStreamUpdate{mType: REMOVE_KEYSPACE_FROM_STREAM,
streamId: streamId,
keyspaceId: keyspaceId,
respCh: respCh,
sessionId: sessionId,
abortRecovery: true,
}
idx.setStreamKeyspaceIdState(streamId, keyspaceId, STREAM_INACTIVE)
isRemoveKeyspace = true
}

//send stream update to mutation manager
if resp := idx.sendStreamUpdateToWorker(cmd, idx.mutMgrCmdCh,
"MutationMgr"); resp.GetMsgType() != MSG_SUCCESS {
if clientCh != nil {
clientCh <- resp
}
respErr := resp.(*MsgError).GetError()
common.CrashOnError(respErr.cause)
}

//send stream update to timekeeper
if resp := idx.sendStreamUpdateToWorker(cmd, idx.tkCmdCh,
"Timekeeper"); resp.GetMsgType() != MSG_SUCCESS {
if clientCh != nil {
clientCh <- resp
}
respErr := resp.(*MsgError).GetError()
common.CrashOnError(respErr.cause)
}

// If removing entire keyspace, also remove the stats for it
if isRemoveKeyspace {
idx.stats.RemoveKeyspaceStats(streamId, keyspaceId)
idx.distributeKeyspaceStatsMapsToWorkers()
}

reqLock := idx.acquireStreamRequestLock(keyspaceId, streamId)
go func(reqLock *kvRequest) {
defer idx.releaseStreamRequestLock(reqLock)
idx.waitStreamRequestLock(reqLock)
retryloop:
for {

if !idx.ValidateKeyspace(streamId, keyspaceId, []string{bucketUUID}) {
logging.Errorf("Indexer::removeIndexesFromStream Keyspace Not Found "+
"For Stream %v KeyspaceId %v", streamId, keyspaceId)
idx.internalRecvCh <- &MsgRecovery{mType: INDEXER_KEYSPACE_NOT_FOUND,
streamId: streamId,
keyspaceId: keyspaceId,
sessionId: sessionId}
break retryloop
}

idx.sendMsgToKVSender(cmd)

if resp, ok := <-respCh; ok {

switch resp.GetMsgType() {

case MSG_SUCCESS:
logging.Infof("Indexer::removeIndexesFromStream Success Stream %v "+
"KeyspaceId %v SessionId %v", streamId, keyspaceId, sessionId)
break retryloop

default:
if idx.getStreamKeyspaceIdState(streamId, keyspaceId) != STREAM_ACTIVE {
logging.Warnf("Indexer::removeIndexesFromStream Stream %v KeyspaceId %v "+
"SessionId %v KeyspaceId stream not active. Aborting.", streamId,
keyspaceId, sessionId)
break retryloop
}

//log and retry for all other responses
respErr := resp.(*MsgError).GetError()
logging.Errorf("Indexer::removeIndexesFromStream - Stream %v KeyspaceId %v"+
"SessionId %v. Error from Projector %v. Retrying.", streamId, keyspaceId,
sessionId, respErr.cause)
time.Sleep(KV_RETRY_INTERVAL * time.Millisecond)

}
}
}
}(reqLock)
}

```

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

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.