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

vickysongang/WolaiWebservice: websocket/order_manager.go; 43 LoC

Open
#14,080 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [vickysongang/WolaiWebservice](https://www.github.com/vickysongang/WolaiWebservice) at [websocket/order_manager.go](https://github.com/vickysongang/WolaiWebservice/blob/f47b71d4703b1043b2478bddd5114cbdb0d9d5ec/websocket/order_manager.go#L386-L428)

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 orderId used in defer or goroutine at line 402

[Click here to see the code in its original context.](https://github.com/vickysongang/WolaiWebservice/blob/f47b71d4703b1043b2478bddd5114cbdb0d9d5ec/websocket/order_manager.go#L386-L428)

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

```go
for orderId, _ := range UserManager.UserOrderDispatchMap[userId] {
order, err := models.ReadOrder(orderId)
if err != nil {
continue
}
if order.Type != models.ORDER_TYPE_GENERAL_INSTANT {
continue
}
if !osm.IsOrderOnline(orderId) {
continue
}
if ok, _ := OrderManager.LockOrder(orderId); !ok {
continue
}

go func() {
orderIdStr := strconv.FormatInt(orderId, 10)
cancelMsg := NewWSMessage("", order.Creator, WS_ORDER2_CANCEL)
cancelMsg.Attribute["orderId"] = orderIdStr
for teacherId, _ := range osm.orderMap[orderId].dispatchMap {
if UserManager.HasUserChan(teacherId) {
cancelMsg.UserId = teacherId
userChan := UserManager.GetUserChan(teacherId)
userChan <- cancelMsg
}
}
if assignId, err := osm.GetCurrentAssign(orderId); err == nil {
if UserManager.HasUserChan(assignId) {
cancelMsg.UserId = assignId
userChan := UserManager.GetUserChan(assignId)
userChan <- cancelMsg
}
}
quitMsg := NewWSMessage("", order.Creator, SIGNAL_ORDER_QUIT)
orderChan, err := osm.GetOrderChan(orderId)
if err == nil {
orderChan <- quitMsg
}
osm.SetOffline(orderId)
}()
osm.SetOrderCancelled(orderId)
osm.UnlockUserCreateOrder(order.Creator)
}

```

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Read websocket/order_manager.go at lines 386-428, beginning with the loop that launches the goroutine using orderId. Check whether the reported range-variable capture can affect the websocket cancellation and quit messages, and review the surrounding order-management behavior. Done means classifying the finding as Bug, Mitigated, or Desirable Behavior with evidence from this code.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.