Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop entity change event loop when controller shuts down. Fixes #1406 #1407

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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