mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Fix race condition in generate task (#1888)
This commit is contained in:
@@ -53,6 +53,8 @@ func (j *GenerateJob) Execute(ctx context.Context, progress *job.Progress) {
|
|||||||
|
|
||||||
queue := make(chan Task, generateQueueSize)
|
queue := make(chan Task, generateQueueSize)
|
||||||
go func() {
|
go func() {
|
||||||
|
defer close(queue)
|
||||||
|
|
||||||
var totals totalsGenerate
|
var totals totalsGenerate
|
||||||
sceneIDs, err := utils.StringSliceToIntSlice(j.input.SceneIDs)
|
sceneIDs, err := utils.StringSliceToIntSlice(j.input.SceneIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -117,8 +119,11 @@ func (j *GenerateJob) Execute(ctx context.Context, progress *job.Progress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wg.Add()
|
wg.Add()
|
||||||
go progress.ExecuteTask(f.GetDescription(), func() {
|
// #1879 - need to make a copy of f - otherwise there is a race condition
|
||||||
f.Start(ctx)
|
// where f is changed when the goroutine runs
|
||||||
|
localTask := f
|
||||||
|
go progress.ExecuteTask(localTask.GetDescription(), func() {
|
||||||
|
localTask.Start(ctx)
|
||||||
wg.Done()
|
wg.Done()
|
||||||
progress.Increment()
|
progress.Increment()
|
||||||
})
|
})
|
||||||
@@ -136,8 +141,6 @@ func (j *GenerateJob) Execute(ctx context.Context, progress *job.Progress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (j *GenerateJob) queueTasks(ctx context.Context, queue chan<- Task) totalsGenerate {
|
func (j *GenerateJob) queueTasks(ctx context.Context, queue chan<- Task) totalsGenerate {
|
||||||
defer close(queue)
|
|
||||||
|
|
||||||
var totals totalsGenerate
|
var totals totalsGenerate
|
||||||
|
|
||||||
const batchSize = 1000
|
const batchSize = 1000
|
||||||
|
|||||||
Reference in New Issue
Block a user