github-vet / github-vet/rangeloop-pointer-findings
paust-team/shapleq: broker/broker.go; 58 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [paust-team/shapleq](https://www.github.com/paust-team/shapleq) at [broker/broker.go](https://github.com/paust-team/shapleq/blob/475bb7fceb84cebdb8149e27ad1d03c95ee1fbb4/broker/broker.go#L270-L327)
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 sc used in defer or goroutine at line 279
[Click here to see the code in its original context.](https://github.com/paust-team/shapleq/blob/475bb7fceb84cebdb8149e27ad1d03c95ee1fbb4/broker/broker.go#L270-L327)
Click here to show the 58 line(s) of Go which triggered the analyzer.
```go
for sc := range scCh {
txMsgCh := make(chan *message.QMessage)
streamMsgCh := make(chan *message.QMessage)
wg.Add(1)
go func() {
defer close(txMsgCh)
defer close(streamMsgCh)
defer wg.Done()
b.sessionMgr.AddSession(sc.session)
defer b.sessionMgr.RemoveSession(sc.session)
sc.session.Open()
defer sc.session.Close()
msgCh, errCh, err := sc.session.ContinuousRead(sc.ctx)
if err != nil {
return
}
for {
select {
case <-sc.ctx.Done():
return
case msg := <-msgCh:
if msg != nil {
if msg.Type() == message.TRANSACTION {
txMsgCh <- msg
} else if msg.Type() == message.STREAM {
streamMsgCh <- msg
}
}
case err := <-errCh:
if err != nil {
pqErr, ok := err.(pqerror.PQError)
if !ok {
sessionErrCh <- internals.SessionError{
PQError: pqerror.UnhandledError{ErrStr: err.Error()},
Session: sc.session,
CancelSession: sc.cancelSession}
} else {
sessionErrCh <- internals.SessionError{
PQError: pqErr,
Session: sc.session,
CancelSession: sc.cancelSession}
}
}
default:
}
runtime.Gosched()
}
}()
transactionalEvents <- internals.EventStream{sc.session, txMsgCh, sc.ctx, sc.cancelSession}
streamingEvents <- internals.EventStream{sc.session, streamMsgCh, sc.ctx, sc.cancelSession}
runtime.Gosched()
}
```
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: 475bb7fceb84cebdb8149e27ad1d03c95ee1fbb4
Contributor guide
No contributing guide indexed for this repository
Research direction
Read broker/broker.go lines 270-327, focusing on the range over scCh and the goroutine and deferred calls that use sc. Check whether the captured range variable can refer to a different iteration, then inspect the repository's existing validation for broker sessions. Done means classifying the finding as Bug, Mitigated, or Desirable Behavior based on the observed behavior.
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
- Clearly specified
- Newbie friendliness
- 42/100