From d0ff409f04670dd8808b8ab742b29b7a0fe40297 Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sat, 29 May 2021 19:41:29 +0100 Subject: [PATCH 1/2] Close the dataRC reader sooner Fix #15932 Signed-off-by: Andrew Thornton --- routers/repo/editor.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 2cc5c1e7f2fa1..3b74373c2f5d9 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -106,7 +106,13 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.NotFound("blob.Data", err) return } - defer dataRc.Close() + closed := false + + defer func() { + if !closed { + dataRc.Close() + } + }() ctx.Data["FileSize"] = blob.Size() ctx.Data["FileName"] = blob.Name() @@ -122,6 +128,11 @@ func editFile(ctx *context.Context, isNewFile bool) { } d, _ := ioutil.ReadAll(dataRc) + if err := dataRc.Close(); err != nil { + log.Error("Error whilst closing blob data: %v", err) + } + closed = true + buf = append(buf, d...) if content, err := charset.ToUTF8WithErr(buf); err != nil { log.Error("ToUTF8WithErr: %v", err) From 3759a6b5bfa17c2be25b10171a3a2e6e36bc821b Mon Sep 17 00:00:00 2001 From: Andrew Thornton Date: Sun, 30 May 2021 10:35:59 +0100 Subject: [PATCH 2/2] as per lunny Signed-off-by: Andrew Thornton --- routers/repo/editor.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/routers/repo/editor.go b/routers/repo/editor.go index 3b74373c2f5d9..2a2c56952d086 100644 --- a/routers/repo/editor.go +++ b/routers/repo/editor.go @@ -106,13 +106,8 @@ func editFile(ctx *context.Context, isNewFile bool) { ctx.NotFound("blob.Data", err) return } - closed := false - defer func() { - if !closed { - dataRc.Close() - } - }() + defer dataRc.Close() ctx.Data["FileSize"] = blob.Size() ctx.Data["FileName"] = blob.Name() @@ -131,7 +126,6 @@ func editFile(ctx *context.Context, isNewFile bool) { if err := dataRc.Close(); err != nil { log.Error("Error whilst closing blob data: %v", err) } - closed = true buf = append(buf, d...) if content, err := charset.ToUTF8WithErr(buf); err != nil {