diff options
author | zeripath <art27@cantab.net> | 2021-05-15 23:46:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-15 23:46:13 +0200 |
commit | 8e32eeb5deed2da2dc2a648f62cba2613b566f71 (patch) | |
tree | 3a253b370978be5438e78c88c2adbdf479b8af5e /modules/eventsource/manager_run.go | |
parent | Create a session on ReverseProxy and ensure that ReverseProxy users cannot ch... (diff) | |
download | forgejo-8e32eeb5deed2da2dc2a648f62cba2613b566f71.tar.xz forgejo-8e32eeb5deed2da2dc2a648f62cba2613b566f71.zip |
Hold the event source when there are no listeners (#15725)
* Hold the event source when there are no listeners
The event source does not need to run when there are no listeners. Therefore
pause it when there are none.
* add some more logging
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to '')
-rw-r--r-- | modules/eventsource/manager_run.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/eventsource/manager_run.go b/modules/eventsource/manager_run.go index ccfe2e0709..60598ecb49 100644 --- a/modules/eventsource/manager_run.go +++ b/modules/eventsource/manager_run.go @@ -34,6 +34,35 @@ loop: timer.Stop() break loop case <-timer.C: + m.mutex.Lock() + connectionCount := len(m.messengers) + if connectionCount == 0 { + log.Trace("Event source has no listeners") + // empty the connection channel + select { + case <-m.connection: + default: + } + } + m.mutex.Unlock() + if connectionCount == 0 { + // No listeners so the source can be paused + log.Trace("Pausing the eventsource") + select { + case <-ctx.Done(): + break loop + case <-m.connection: + log.Trace("Connection detected - restarting the eventsource") + // OK we're back so lets reset the timer and start again + // We won't change the "then" time because there could be concurrency issues + select { + case <-timer.C: + default: + } + continue + } + } + now := timeutil.TimeStampNow().Add(-2) uidCounts, err := models.GetUIDsAndNotificationCounts(then, now) |