Skip to content

Commit 42c97a5

Browse files
committed
Prevent loop if there is an error in GetNotificationCount
If the context is cancelled `.NotificationUnreadCount` in a template can cause an infinite loop with `ctx.ServerError()` being called, which creates a template that then calls `.NotificationUnreadCount` calling `GetNotificationCount()` with the cancelled context resulting in an error that calls `ctx.ServerError`... and so on... This PR simply stops calling `ctx.ServerError` in the error handler code for `.NotificationUnreadCount` as we have already started rendering and so it is too late to call `ctx.ServerError`. Additionally we skip logging the error if it's a context cancelled error. Fix go-gitea#19793 Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 4266bd9 commit 42c97a5

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

routers/web/user/notification.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package user
66

77
import (
8+
goctx "context"
89
"errors"
910
"fmt"
1011
"net/http"
@@ -14,6 +15,7 @@ import (
1415
"code.gitea.io/gitea/models"
1516
"code.gitea.io/gitea/modules/base"
1617
"code.gitea.io/gitea/modules/context"
18+
"code.gitea.io/gitea/modules/log"
1719
"code.gitea.io/gitea/modules/setting"
1820
"code.gitea.io/gitea/modules/structs"
1921
)
@@ -36,7 +38,9 @@ func GetNotificationCount(c *context.Context) {
3638
c.Data["NotificationUnreadCount"] = func() int64 {
3739
count, err := models.GetNotificationCount(c, c.Doer, models.NotificationStatusUnread)
3840
if err != nil {
39-
c.ServerError("GetNotificationCount", err)
41+
if err != goctx.Canceled {
42+
log.Error("Unable to GetNotificationCount for user:%-v: %v", c.Doer, err)
43+
}
4044
return -1
4145
}
4246

0 commit comments

Comments
 (0)