1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-07-19 17:49:39 +02:00

fix: ignore "Close" error when uploading container blob (#8527)

https://github.com/go-gitea/gitea/pull/34620/files

(cherry picked from commit 7a59f5a8253402d6f98234bf0047ec53156d3af9)

## Testing

Ask @viceice to run the reproducer in his environment once the v12 backport lands

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8527
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
This commit is contained in:
Earl Warren 2025-07-16 15:23:52 +02:00
parent d61bd928a4
commit ec8c0a50c2

View file

@ -399,12 +399,7 @@ func EndUploadBlob(ctx *context.Context) {
} }
return return
} }
doClose := true defer uploader.Close()
defer func() {
if doClose {
uploader.Close()
}
}()
if ctx.Req.Body != nil { if ctx.Req.Body != nil {
if err := uploader.Append(ctx, ctx.Req.Body); err != nil { if err := uploader.Append(ctx, ctx.Req.Body); err != nil {
@ -437,11 +432,10 @@ func EndUploadBlob(ctx *context.Context) {
return return
} }
if err := uploader.Close(); err != nil { // There was a strange bug: the "Close" fails with error "close .../tmp/package-upload/....: file already closed"
apiError(ctx, http.StatusInternalServerError, err) // AFAIK there should be no other "Close" call to the uploader between NewBlobUploader and this line.
return // At least it's safe to call Close twice, so ignore the error.
} _ = uploader.Close()
doClose = false
if err := container_service.RemoveBlobUploadByID(ctx, uploader.ID); err != nil { if err := container_service.RemoveBlobUploadByID(ctx, uploader.ID); err != nil {
apiError(ctx, http.StatusInternalServerError, err) apiError(ctx, http.StatusInternalServerError, err)