Skip to content

Commit

Permalink
Add a timeout to the context to cleanup any remaining goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Apr 10, 2024
1 parent b9a6953 commit 1da8eb2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/node/manager/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ func (e *NodeEventEmitter) EmitEvent(ctx context.Context, info models.NodeInfo,
completedChan := make(chan struct{})
wg := sync.WaitGroup{}

newCtx, cancel := context.WithCancel(ctx)
defer cancel()

for _, hlr := range e.callbacks {
wg.Add(1)
go func(handler NodeEventHandler) {
go func(handler NodeEventHandler, ctx context.Context) {
defer wg.Done()

handler.HandleNodeEvent(ctx, info, event)
wg.Done()
}(hlr)
}(hlr, newCtx)
}

// Wait for the waitgroup and then close the channel to signal completion. This allows
Expand Down

0 comments on commit 1da8eb2

Please sign in to comment.