]> source.dussan.org Git - gitea.git/commitdiff
If rendering has failed due to a net.OpError stop rendering (#18642) (#18645)
authorzeripath <art27@cantab.net>
Mon, 7 Feb 2022 01:25:05 +0000 (01:25 +0000)
committerGitHub <noreply@github.com>
Mon, 7 Feb 2022 01:25:05 +0000 (09:25 +0800)
Backport #18642

When a net.OpError occurs during rendering the underlying connection is essentially
dead and therefore attempting to render further data will only cause further errors.

Therefore in serverErrorInternal detect if the passed in error is an OpError and
if so do not attempt any further rendering.

Fix #18629

Signed-off-by: Andrew Thornton <art27@cantab.net>
modules/context/context.go

index dd571b4d787765d48051ff0a5a0bc431de27f283..c7b9c0615ce1b2ee96a2e7a9514a38215f799e5b 100644 (file)
@@ -9,9 +9,11 @@ import (
        "context"
        "crypto/sha256"
        "encoding/hex"
+       "errors"
        "html"
        "html/template"
        "io"
+       "net"
        "net/http"
        "net/url"
        "path"
@@ -264,6 +266,12 @@ func (ctx *Context) ServerError(logMsg string, logErr error) {
 func (ctx *Context) serverErrorInternal(logMsg string, logErr error) {
        if logErr != nil {
                log.ErrorWithSkip(2, "%s: %v", logMsg, logErr)
+               if errors.Is(logErr, &net.OpError{}) {
+                       // This is an error within the underlying connection
+                       // and further rendering will not work so just return
+                       return
+               }
+
                if !setting.IsProd {
                        ctx.Data["ErrorMsg"] = logErr
                }