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

pranjalv123/mexos: src/shardkv/server.go; 91 LoC

Open
#9,936 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 [pranjalv123/mexos](https://www.github.com/pranjalv123/mexos) at [src/shardkv/server.go](https://github.com/pranjalv123/mexos/blob/6712af6a7bbe280d4ab93ac5b3bf90ba43be400b/src/shardkv/server.go#L1470-L1560)

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 server used in defer or goroutine at line 1540

[Click here to see the code in its original context.](https://github.com/pranjalv123/mexos/blob/6712af6a7bbe280d4ab93ac5b3bf90ba43be400b/src/shardkv/server.go#L1470-L1560)

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

```go
for index, server := range servers {
if index == kv.me {
continue
}
// Keep getting shard data until entire store is transfered
// or until server doesn't respond
keysReceived := make(map[string]bool)
numTries := 0
badResponse := false
for !kv.dead && !haveShard && !badResponse {
if len(keysReceived) > 0 {
fmt.Printf("\nAsking for more!")
}
DPrintfPersist("\n\t%v-%v: Asking %v for shard %v", kv.gid, kv.me, index, shard)
args := RecoverArgs{kv.config.Num, shard, keysReceived, fmt.Sprintf("%v-%v", kv.gid, kv.me)}
var reply RecoverReply
ok := call(server, "ShardKV.FetchRecovery", args, &reply, kv.network)
if ok && !reply.Err {
DPrintf("\n\t: %v-%v Got shard %v from %v\n", kv.gid, kv.me, shard, index)
for k, v := range reply.Store {
kv.putValue(k, v)
keysReceived[k] = true
}
for clientID, value := range reply.Response {
kv.putResponse(-1, clientID, value)
}
for opID, seen := range reply.Seen {
kv.putSeen(opID, seen)
}
// If that was the entire store, then exit
// otherwise ask for more of the store
if reply.Complete {
haveShard = true
// Keep sending ack of Fetch until success
waitChan := make(chan int)
go func(srv string) {
ackSuccess := false
ackArgs := &FetchArgs{}
ackArgs.Sender = fmt.Sprintf("%v-%v", kv.gid, kv.me)
var ackReply FetchReply
waitChan <- 1
for !kv.dead && !ackSuccess {
ackOK := call(srv, "ShardKV.FetchComplete", ackArgs, &ackReply, kv.network)
ackSuccess = ackOK && ackReply.Complete
if !ackSuccess {
time.Sleep(recoveryRetryDelay * time.Millisecond)
}
}
}(server)
<-waitChan
}
}
if reply.Err && ok && len(keysReceived) == 0 {
// Move on to another peer if this one got an eror
// or didn't respond, but only move on if
// we haven't previously received a good reply
badResponse = true
}
if !ok && numTries > 5 {
badResponse = true
// If we are declaring it dead,
// Send it an ack of Fetch until success
// In case it wakes up
waitChan := make(chan int)
go func(srv string) {
ackSuccess := false
ackArgs := &FetchArgs{}
ackArgs.Sender = fmt.Sprintf("%v-%v", kv.gid, kv.me)
var ackReply FetchReply
waitChan <- 1
for srv == server {
time.Sleep(10 * time.Millisecond)
}
for !kv.dead && !ackSuccess && (srv != server) {
DPrintf("\n%v.%v: Sending fetch complete to %s", kv.gid, kv.me, server)
ackOK := call(srv, "ShardKV.FetchComplete", ackArgs, &ackReply, kv.network)
ackSuccess = ackOK && ackReply.Complete
if !ackSuccess {
time.Sleep(recoveryRetryDelay * time.Millisecond)
}
}
DPrintf("\n%v.%v: Done sending fetch complete to %s", kv.gid, kv.me, server)
}(server)
<-waitChan
}
if !ok {
numTries++
time.Sleep(100 * time.Millisecond)
}
}
}

```

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: 6712af6a7bbe280d4ab93ac5b3bf90ba43be400b

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.