github-vet / github-vet/rangeloop-pointer-findings
communitybridge/easycla: cla-backend-go/v2/dynamo_events/service.go; 58 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [communitybridge/easycla](https://www.github.com/communitybridge/easycla) at [cla-backend-go/v2/dynamo_events/service.go](https://github.com/communitybridge/easycla/blob/232f9d9dcfbccd8531f6feb4c44a62e80490fa07/cla-backend-go/v2/dynamo_events/service.go#L159-L216)
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 event used in defer or goroutine at line 194
[Click here to see the code in its original context.](https://github.com/communitybridge/easycla/blob/232f9d9dcfbccd8531f6feb4c44a62e80490fa07/cla-backend-go/v2/dynamo_events/service.go#L159-L216)
Click here to show the 58 line(s) of Go which triggered the analyzer.
```go
for _, event := range dynamoDBEvents.Records {
tableName := strings.Split(event.EventSourceArn, "/")[1]
fields := logrus.Fields{
"functionName": "dynamo_events.ProcessEvents",
"table_name": tableName,
"eventID": event.EventID,
"eventName": event.EventName,
"eventSource": event.EventSource,
// Dumping the event is super verbose
// "event": event,
}
// Generates a ton of output
// b, _ := json.Marshal(events) // nolint
//fields["events_data"] = string(b)
log.WithFields(fields).Debug("processing event record")
key := fmt.Sprintf("%s:%s", tableName, event.EventName)
// If we have any functions registered
if len(s.functions[key]) > 0 {
// Setup a wait group for the go routine
var wg sync.WaitGroup
wg.Add(len(s.functions[key]))
// For each function handler...
for _, eventHandlerFunction := range s.functions[key] {
go func(f EventHandlerFunc, e events.DynamoDBEventRecord) {
defer wg.Done()
fnType := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
log.WithFields(fields).
WithField("key", key).
WithField("functionType", fnType).
Debug("invoking handler")
err := f(event)
if err != nil {
log.WithFields(fields).
WithField("key", key).
WithField("functionType", fnType).
WithError(err).
WithField("event", e).
Error("unable to process event")
}
log.WithFields(fields).
WithField("key", key).
WithField("functionType", fnType).
Debug("done with handler")
}(eventHandlerFunction, event)
}
// Wait until the registered handlers/functions have completed for this event type...
log.WithFields(fields).Debugf("waiting for %d event handler functions to complete...", len(s.functions[key]))
wg.Wait()
log.WithFields(fields).Debugf("%d event handler functions completed", len(s.functions[key]))
}
}
```
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: 232f9d9dcfbccd8531f6feb4c44a62e80490fa07
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.