From 297346a7628c726a02fa14cbf1ba3edec5122ecd Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Thu, 21 Apr 2022 18:55:44 +0200 Subject: [PATCH] RepoAssignment ensure to close before overwrite (#19449) (#19460) * check if GitRepo already open and close if * Only run RepoAssignment once --- modules/context/repo.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/modules/context/repo.go b/modules/context/repo.go index ac00c2c10..4eeab710f 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -410,6 +410,12 @@ func RepoIDAssignment() func(ctx *Context) { // RepoAssignment returns a middleware to handle repository assignment func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { + if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce { + log.Trace("RepoAssignment was exec already, skipping second call ...") + return + } + ctx.Data["repoAssignmentExecuted"] = true + var ( owner *user_model.User err error @@ -592,6 +598,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) { ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err) return } + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + } ctx.Repo.GitRepo = gitRepo // We opened it, we should close it