Skip to content

Commit eba0786

Browse files
authored
Prevent deadlock in create issue (#17970)
1 parent 39eb824 commit eba0786

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

models/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (issue *Issue) isTimetrackerEnabled(ctx context.Context) bool {
141141
log.Error(fmt.Sprintf("loadRepo: %v", err))
142142
return false
143143
}
144-
return issue.Repo.IsTimetrackerEnabled()
144+
return issue.Repo.IsTimetrackerEnabledCtx(ctx)
145145
}
146146

147147
// GetPullRequest returns the issue pull request

models/repo/issue.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ func (repo *Repository) CanEnableTimetracker() bool {
2828

2929
// IsTimetrackerEnabled returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
3030
func (repo *Repository) IsTimetrackerEnabled() bool {
31+
return repo.IsTimetrackerEnabledCtx(db.DefaultContext)
32+
}
33+
34+
// IsTimetrackerEnabledCtx returns whether or not the timetracker is enabled. It returns the default value from config if an error occurs.
35+
func (repo *Repository) IsTimetrackerEnabledCtx(ctx context.Context) bool {
3136
if !setting.Service.EnableTimetracking {
3237
return false
3338
}
3439

3540
var u *RepoUnit
3641
var err error
37-
if u, err = repo.GetUnit(unit.TypeIssues); err != nil {
42+
if u, err = repo.GetUnitCtx(ctx, unit.TypeIssues); err != nil {
3843
return setting.Service.DefaultEnableTimetracking
3944
}
4045
return u.IssuesConfig().EnableTimetracker
@@ -59,7 +64,7 @@ func (repo *Repository) IsDependenciesEnabled() bool {
5964
func (repo *Repository) IsDependenciesEnabledCtx(ctx context.Context) bool {
6065
var u *RepoUnit
6166
var err error
62-
if u, err = repo.getUnit(ctx, unit.TypeIssues); err != nil {
67+
if u, err = repo.GetUnitCtx(ctx, unit.TypeIssues); err != nil {
6368
log.Trace("%s", err)
6469
return setting.Service.DefaultEnableDependencies
6570
}

models/repo/repo.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,11 @@ func (repo *Repository) MustGetUnit(tp unit.Type) *RepoUnit {
312312

313313
// GetUnit returns a RepoUnit object
314314
func (repo *Repository) GetUnit(tp unit.Type) (*RepoUnit, error) {
315-
return repo.getUnit(db.DefaultContext, tp)
315+
return repo.GetUnitCtx(db.DefaultContext, tp)
316316
}
317317

318-
func (repo *Repository) getUnit(ctx context.Context, tp unit.Type) (*RepoUnit, error) {
318+
// GetUnitCtx returns a RepoUnit object
319+
func (repo *Repository) GetUnitCtx(ctx context.Context, tp unit.Type) (*RepoUnit, error) {
319320
if err := repo.LoadUnits(ctx); err != nil {
320321
return nil, err
321322
}

0 commit comments

Comments
 (0)