Skip to content

Commit 297346a

Browse files
authored
RepoAssignment ensure to close before overwrite (#19449) (#19460)
* check if GitRepo already open and close if * Only run RepoAssignment once
1 parent acd6480 commit 297346a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Diff for: modules/context/repo.go

+9
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ func RepoIDAssignment() func(ctx *Context) {
410410

411411
// RepoAssignment returns a middleware to handle repository assignment
412412
func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
413+
if _, repoAssignmentOnce := ctx.Data["repoAssignmentExecuted"]; repoAssignmentOnce {
414+
log.Trace("RepoAssignment was exec already, skipping second call ...")
415+
return
416+
}
417+
ctx.Data["repoAssignmentExecuted"] = true
418+
413419
var (
414420
owner *user_model.User
415421
err error
@@ -592,6 +598,9 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
592598
ctx.ServerError("RepoAssignment Invalid repo "+repo_model.RepoPath(userName, repoName), err)
593599
return
594600
}
601+
if ctx.Repo.GitRepo != nil {
602+
ctx.Repo.GitRepo.Close()
603+
}
595604
ctx.Repo.GitRepo = gitRepo
596605

597606
// We opened it, we should close it

0 commit comments

Comments
 (0)