lib/model: Stop summary sender faster (ref #6319) (#6341)

One of the causes of "panic: database is closed" is that we try to send
summaries after it's been closed. Calculating summaries can take a long
time and if we have a lot of folders it's not unreasonable to think
that we might be stopped in this loop, so prepare to bail here.

* push
This commit is contained in:
Jakob Borg 2020-02-14 08:11:54 +01:00 committed by GitHub
parent 05e23f1991
commit bb375b1aff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 3 deletions

View File

@ -270,7 +270,12 @@ func (c *folderSummaryService) calculateSummaries(ctx context.Context) {
case <-pump.C:
t0 := time.Now()
for _, folder := range c.foldersToHandle() {
c.sendSummary(folder)
select {
case <-ctx.Done():
return
default:
}
c.sendSummary(ctx, folder)
}
// We don't want to spend all our time calculating summaries. Lets
@ -280,7 +285,7 @@ func (c *folderSummaryService) calculateSummaries(ctx context.Context) {
pump.Reset(wait)
case folder := <-c.immediate:
c.sendSummary(folder)
c.sendSummary(ctx, folder)
case <-ctx.Done():
return
@ -313,7 +318,7 @@ func (c *folderSummaryService) foldersToHandle() []string {
}
// sendSummary send the summary events for a single folder
func (c *folderSummaryService) sendSummary(folder string) {
func (c *folderSummaryService) sendSummary(ctx context.Context, folder string) {
// The folder summary contains how many bytes, files etc
// are in the folder and how in sync we are.
data, err := c.Summary(folder)
@ -326,6 +331,12 @@ func (c *folderSummaryService) sendSummary(folder string) {
})
for _, devCfg := range c.cfg.Folders()[folder].Devices {
select {
case <-ctx.Done():
return
default:
}
if devCfg.DeviceID.Equals(c.id) {
// We already know about ourselves.
continue