Skip to content

Commit

Permalink
fix delete lock scope
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Sep 21, 2024
1 parent 5589b23 commit 09590b4
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions pkg/download/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,19 +560,19 @@ func (d *Downloader) Delete(filter *TaskFilter, force bool) (err error) {
}

func (d *Downloader) deleteAll() (err error) {
for _, task := range d.tasks {
if err = d.doDelete(task, true); err != nil {
return
}
}

func() {
d.lock.Lock()
defer d.lock.Unlock()

d.tasks = make([]*Task, 0)
d.waitTasks = make([]*Task, 0)
}()

for _, task := range d.tasks {
if err = d.doDelete(task, true); err != nil {
return

Check warning on line 573 in pkg/download/downloader.go

View check run for this annotation

Codecov / codecov/patch

pkg/download/downloader.go#L572-L573

Added lines #L572 - L573 were not covered by tests
}
}
return
}

Expand All @@ -598,9 +598,6 @@ func (d *Downloader) Stats(id string) (sr any, err error) {

func (d *Downloader) doDelete(task *Task, force bool) (err error) {
err = func() error {
d.lock.Lock()
defer d.lock.Unlock()

if err := d.storage.Delete(bucketTask, task.ID); err != nil {
return err
}
Expand Down Expand Up @@ -628,10 +625,10 @@ func (d *Downloader) doDelete(task *Task, force bool) (err error) {
task = nil
return nil
}()

if err != nil {
d.Logger.Error().Stack().Err(err).Msgf("delete task failed, task id: %s", task.ID)
}

return
}

Expand Down

0 comments on commit 09590b4

Please sign in to comment.