github-vet / github-vet/rangeloop-pointer-findings
portworx/kvdb: test/kv.go; 33 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [portworx/kvdb](https://www.github.com/portworx/kvdb) at [test/kv.go](https://github.com/portworx/kvdb/blob/b312c7519467b2910b6d8ecc24016c14a5ec5146/test/kv.go#L851-L883)
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 lockMethod used in defer or goroutine at line 873
[Click here to see the code in its original context.](https://github.com/portworx/kvdb/blob/b312c7519467b2910b6d8ecc24016c14a5ec5146/test/kv.go#L851-L883)
Click here to show the 33 line(s) of Go which triggered the analyzer.
```go
for _, lockMethod := range lockMethods {
// Try to take the lock again
// We need this test for consul to check if LockDelay is not set
fmt.Println("lock before restarting kvdb")
kvPairBeforeRestart, err := lockMethod("key3")
assert.NoError(t, err, "Unable to take a lock")
fmt.Println("stopping kvdb")
err = stop()
assert.NoError(t, err, "Unable to stop kvdb")
// Unlock the key
go func() { kv.Unlock(kvPairBeforeRestart) }()
time.Sleep(30 * time.Second)
fmt.Println("starting kvdb")
err = start(false)
assert.NoError(t, err, "Unable to start kvdb")
time.Sleep(40 * time.Second)
lockChan := make(chan int)
var kvPair3 *kvdb.KVPair
go func() {
kvPair3, err = lockMethod("key3")
lockChan <- 1
}()
select {
case <-time.After(20 * time.Second):
assert.Fail(t, "Unable to take a lock whose session is expired")
case <-lockChan:
}
err = kv.Unlock(kvPair3)
assert.NoError(t, err, "unable to unlock")
}
```
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: b312c7519467b2910b6d8ecc24016c14a5ec5146
Contributor guide
No contributing guide indexed for this repository
Research direction
Read test/kv.go around lines 851-883, starting with the range over lockMethods and the two goroutines that use lockMethod. Determine whether the reported range-loop capture is a real bug in this test, then inspect the surrounding test behavior before choosing Bug, Mitigated, or Desirable Behavior. Done means the finding has a justified classification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100