Add lock for parallel maven upload (#31954)

Backport #31851 
Fix #30171
This commit is contained in:
Lunny Xiao
2024-09-03 14:33:28 +08:00
committed by GitHub
parent d3b0bc22c0
commit 9c990ac043
2 changed files with 39 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ import (
"code.gitea.io/gitea/modules/log"
packages_module "code.gitea.io/gitea/modules/packages"
maven_module "code.gitea.io/gitea/modules/packages/maven"
"code.gitea.io/gitea/modules/sync"
"code.gitea.io/gitea/routers/api/packages/helper"
"code.gitea.io/gitea/services/context"
packages_service "code.gitea.io/gitea/services/packages"
@@ -223,6 +224,8 @@ func servePackageFile(ctx *context.Context, params parameters, serveContent bool
helper.ServePackageFile(ctx, s, u, pf, opts)
}
var mavenUploadLock = sync.NewExclusivePool()
// UploadPackageFile adds a file to the package. If the package does not exist, it gets created.
func UploadPackageFile(ctx *context.Context) {
params, err := extractPathParameters(ctx)
@@ -241,6 +244,9 @@ func UploadPackageFile(ctx *context.Context) {
packageName := params.GroupID + "-" + params.ArtifactID
mavenUploadLock.CheckIn(packageName)
defer mavenUploadLock.CheckOut(packageName)
buf, err := packages_module.CreateHashedBufferFromReader(ctx.Req.Body)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)