Skip to content

Commit

Permalink
fix: event dispatcher goroutine captures only the last loop index whe…
Browse files Browse the repository at this point in the history
…n asynchronously handling events with e.config.AsyncEventsEnabled == true (#250)

Co-authored-by: jkdlgy <65353031+jkdlgy@users.noreply.github.com >
  • Loading branch information
jkdlgy committed Mar 21, 2023
1 parent 8369a3b commit 9977445
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bot/event_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ func (e *eventManagerImpl) DispatchEvent(event Event) {
defer e.eventListenerMu.Unlock()
for i := range e.config.EventListeners {
if e.config.AsyncEventsEnabled {
go func() {
go func(i int) {
defer func() {
if r := recover(); r != nil {
e.config.Logger.Errorf("recovered from panic in event listener: %+v\nstack: %s", r, string(debug.Stack()))
return
}
}()
e.config.EventListeners[i].OnEvent(event)
}()
}(i)
continue
}
e.config.EventListeners[i].OnEvent(event)
Expand Down

0 comments on commit 9977445

Please sign in to comment.