github-vet / github-vet/rangeloop-pointer-findings
matrix-org/dendrite: appservice/query/query.go; 47 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [matrix-org/dendrite](https://www.github.com/matrix-org/dendrite) at [appservice/query/query.go](https://github.com/matrix-org/dendrite/blob/a85051ca9de82756a94f1ea6870de9bd140a6b20/appservice/query/query.go#L56-L102)
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 appservice used in defer or goroutine at line 77
[Click here to see the code in its original context.](https://github.com/matrix-org/dendrite/blob/a85051ca9de82756a94f1ea6870de9bd140a6b20/appservice/query/query.go#L56-L102)
Click here to show the 47 line(s) of Go which triggered the analyzer.
```go
for _, appservice := range a.Cfg.Derived.ApplicationServices {
if appservice.URL != "" && appservice.IsInterestedInRoomAlias(request.Alias) {
// The full path to the rooms API, includes hs token
URL, err := url.Parse(appservice.URL + roomAliasExistsPath)
URL.Path += request.Alias
apiURL := URL.String() + "?access_token=" + appservice.HSToken
// Send a request to each application service. If one responds that it has
// created the room, immediately return.
req, err := http.NewRequest(http.MethodGet, apiURL, nil)
if err != nil {
return err
}
req = req.WithContext(ctx)
resp, err := a.HTTPClient.Do(req)
if resp != nil {
defer func() {
err = resp.Body.Close()
if err != nil {
log.WithFields(log.Fields{
"appservice_id": appservice.ID,
"status_code": resp.StatusCode,
}).WithError(err).Error("Unable to close application service response body")
}
}()
}
if err != nil {
log.WithError(err).Errorf("Issue querying room alias on application service %s", appservice.ID)
return err
}
switch resp.StatusCode {
case http.StatusOK:
// OK received from appservice. Room exists
response.AliasExists = true
return nil
case http.StatusNotFound:
// Room does not exist
default:
// Application service reported an error. Warn
log.WithFields(log.Fields{
"appservice_id": appservice.ID,
"status_code": resp.StatusCode,
}).Warn("Application service responded with non-OK status code")
}
}
}
```
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: a85051ca9de82756a94f1ea6870de9bd140a6b20
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading appservice/query/query.go around lines 56-102, especially the deferred response-body close and its use of the range variable. Check the surrounding query behavior and existing Go tests, then verify that response-close logging identifies the correct application service for every iteration. Done means the reported range-loop issue is addressed or shown not to affect behavior, with relevant tests passing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100