Skip to content

Commit

Permalink
Merge pull request #1407 from openziti/shutdown-entity-change-goroutines
Browse files Browse the repository at this point in the history
stop entity change event loop when controller shuts down. Fixes #1406
  • Loading branch information
plorenz authored Oct 5, 2023
2 parents a0aab98 + 4c803d9 commit c57a81c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions controller/events/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func NewDispatcher(closeNotify <-chan struct{}) *Dispatcher {
result := &Dispatcher{
closeNotify: closeNotify,
entityChangeEventsDispatcher: entityChangeEventDispatcher{
closeNotify: closeNotify,
notifyCh: make(chan struct{}, 1),
globalMetadata: map[string]any{},
},
Expand Down
9 changes: 8 additions & 1 deletion controller/events/dispatcher_entity_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func bytesToTxId(b []byte) uint64 {
type entityChangeEventDispatcher struct {
network *network.Network
dispatcher *Dispatcher
closeNotify <-chan struct{}
notifyCh chan struct{}
globalMetadata map[string]any
}
Expand Down Expand Up @@ -298,12 +299,18 @@ func (self *entityChangeEventDispatcher) notifyFlush() {
func (self *entityChangeEventDispatcher) flushLoop() {
for {
// wait to be notified of an event
<-self.notifyCh
select {
case <-self.closeNotify:
return
case <-self.notifyCh:
}

// wait until we've not gotten an event for 5 seconds before cleaning up
flushed := false
for !flushed {
select {
case <-self.closeNotify:
return
case <-self.notifyCh:
case <-time.After(5 * time.Second):
pfxlog.Logger().Debug("cleaning up entity change events")
Expand Down

0 comments on commit c57a81c

Please sign in to comment.