mirror of
				https://codeberg.org/forgejo/forgejo.git
				synced 2025-11-04 08:21:11 +00:00 
			
		
		
		
	[v12.0/forgejo] fix: ignore "Close" error when uploading container blob (#8528)
**Backport:** https://codeberg.org/forgejo/forgejo/pulls/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: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8528 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Reviewed-by: Michael Kriese <michael.kriese@gmx.de> Co-authored-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org> Co-committed-by: forgejo-backport-action <forgejo-backport-action@noreply.codeberg.org>
This commit is contained in:
		
					parent
					
						
							
								48920461a2
							
						
					
				
			
			
				commit
				
					
						3dd9172fd6
					
				
			
		
					 1 changed files with 5 additions and 11 deletions
				
			
		| 
						 | 
					@ -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)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue