github-vet / github-vet/rangeloop-pointer-findings
pranjalv123/mexos: src/shardkv/server.go; 95 LoC
- 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#L588-L682)
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 srv used in defer or goroutine at line 660
[Click here to see the code in its original context.](https://github.com/pranjalv123/mexos/blob/6712af6a7bbe280d4ab93ac5b3bf90ba43be400b/src/shardkv/server.go#L588-L682)
Click here to show the 95 line(s) of Go which triggered the analyzer.
```go
for sid, srv := range servers {
keysReceived := make(map[string]bool)
numTries := 0
badResponse := false
// Keep getting data until entire shard is transferred
for !kv.dead && !haveShard && !badResponse {
if len(keysReceived) > 0 {
//fmt.Printf("\nAsking for more!")
}
DPrintf("%d.%d.%d) Attempting to get Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
fmt.Printf("\n%d.%d.%d) Attempting to get Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
args := &FetchArgs{newConfig.Num, shard, keysReceived, fmt.Sprintf("%v-%v", kv.gid, kv.me)}
var reply FetchReply
ok := call(srv, "ShardKV.Fetch", args, &reply, kv.network)
if ok && (reply.Err == OK) {
DPrintf("%d.%d.%d) Got Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
//fmt.Printf("\n%d.%d.%d) Got Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
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, _ := range reply.Seen {
kv.putSeen(opID, true)
}
if reply.Complete {
DPrintf("%d.%d.%d) Got Complete Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
fmt.Printf("\n%d.%d.%d) Got Complete Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
haveShard = true
// Keep sending ack of Fetch until success
waitChan := make(chan int)
go func(server string) {
ackSuccess := false
ackArgs := &FetchArgs{}
ackArgs.Sender = fmt.Sprintf("%v-%v", kv.gid, kv.me)
var ackReply FetchReply
waitChan <- 1
for !kv.dead && !ackSuccess {
DPrintf("\n%v.%v: Sending fetch complete to %s", kv.gid, kv.me, server)
ackOK := call(server, "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)
//fmt.Printf("\n%v.%v: Done sending fetch complete to %s", kv.gid, kv.me, server)
}(srv)
<-waitChan
}
}
if ok && (reply.Err != OK) && len(keysReceived) == 0 {
DPrintf("%d.%d.%d) Failed to get Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
badResponse = true
}
if !ok && numTries > 5 {
DPrintf("%d.%d.%d) Failed to get Shard %d from %d.%d\n", kv.gid, kv.me, kv.config.Num, shard, otherGID, sid)
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(server string) {
ackSuccess := false
ackArgs := &FetchArgs{}
ackArgs.Sender = fmt.Sprintf("%v-%v", kv.gid, kv.me)
var ackReply FetchReply
waitChan <- 1
// Wait until outer loop moves on from this server
// (should be very quick)
for srv == server {
time.Sleep(10 * time.Millisecond)
}
// Keep sending ack until success or until outer loop
// decides to try this peer again
for !kv.dead && !ackSuccess && (srv != server) {
DPrintf("\n%v.%v: Sending fetch complete to %s", kv.gid, kv.me, server)
ackOK := call(server, "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)
}(srv)
<-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.