diff options
author | zeripath <art27@cantab.net> | 2020-03-29 20:51:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-29 20:51:14 +0100 |
commit | d01763ee140bc92ec2f487259894ebc22d13a79f (patch) | |
tree | ecb52adcc711a5fe7cae8dafb1bcb9d0d16e2154 /routers | |
parent | 20d4f9206d8d538fecec28816839320f1c52bac0 (diff) | |
download | gitea-d01763ee140bc92ec2f487259894ebc22d13a79f.tar.gz gitea-d01763ee140bc92ec2f487259894ebc22d13a79f.zip |
Protect against NPEs in notifications list (#10879)
Unfortunately there appears to be potential race with notifications
being set before the associated issue has been committed.
This PR adds protection in to the notifications list to log any failures
and remove these notifications from the display.
References #10815 - and prevents the panic but does not completely fix
this.
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/user/notification.go | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/routers/user/notification.go b/routers/user/notification.go index d0ab3dbe88..74803f149e 100644 --- a/routers/user/notification.go +++ b/routers/user/notification.go @@ -81,24 +81,39 @@ func Notifications(c *context.Context) { return } - repos, err := notifications.LoadRepos() + failCount := 0 + + repos, failures, err := notifications.LoadRepos() if err != nil { c.ServerError("LoadRepos", err) return } + notifications = notifications.Without(failures) if err := repos.LoadAttributes(); err != nil { c.ServerError("LoadAttributes", err) return } + failCount += len(failures) - if err := notifications.LoadIssues(); err != nil { + failures, err = notifications.LoadIssues() + if err != nil { c.ServerError("LoadIssues", err) return } - if err := notifications.LoadComments(); err != nil { + notifications = notifications.Without(failures) + failCount += len(failures) + + failures, err = notifications.LoadComments() + if err != nil { c.ServerError("LoadComments", err) return } + notifications = notifications.Without(failures) + failCount += len(failures) + + if failCount > 0 { + c.Flash.Error(fmt.Sprintf("ERROR: %d notifications were removed due to missing parts - check the logs", failCount)) + } title := c.Tr("notifications") if status == models.NotificationStatusUnread && total > 0 { |