Baseflow / Baseflow/flutter_cache_manager

Race condition when downloading the same URL with ignoreMemCache=true

Đang mở
#338 1 bình luận 2 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Dart
Star
809
Fork
510
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
1

Mô tả

## 🐛 Bug Report

I have been seeing the following error message in `flutter_cache_manager` version `3.1.2`:

```
I/flutter (26728): 2021-10-02 16:48:34.376318 SEVERE main - [guarded]
I/flutter (26728): ### _CastError: Null check operator used on a null value
I/flutter (26728): #0 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:65:33)
I/flutter (26728): #1 WebHelper._checkQueue (package:flutter_cache_manager/src/web/web_helper.dart:84:5)
I/flutter (26728): #2 WebHelper._downloadOrAddToQueue (package:flutter_cache_manager/src/web/web_helper.dart:77:7)
I/flutter (26728):
```

### Reproduction steps

I think this happens when I download the same URL at the same time with `ignoreMemCache=true`

In WebHelper if the `downloadFile` method is called with the same URL/key the `Subject` of `_memCache` is overwritten:

https://github.com/Baseflow/flutter_cache_manager/blob/f591b5383de3188115a5140daba4d0a05a3a7a10/flutter_cache_manager/lib/src/web/web_helper.dart#L44-L46

But the first request still deletes it from `_memCache` without checking if it was ignored during the download call:

https://github.com/Baseflow/flutter_cache_manager/blob/f591b5383de3188115a5140daba4d0a05a3a7a10/flutter_cache_manager/lib/src/web/web_helper.dart#L73-L76

I'm actually not sure the `ignoreMemCache` flag does what I want it to do.

Basically I want to force a redownload of the URL without clearing the cache item first.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu trong flutter_cache_manager/lib/src/web/web_helper.dart, đặc biệt là tại phép gán _memCache quanh các dòng 44-46 và phần dọn dẹp quanh các dòng 73-76. Tái hiện các lần tải xuống đồng thời của cùng một URL với ignoreMemCache=true và theo dõi cách Subject bị ghi đè rồi bị xóa. Được xem là hoàn tất khi race condition không còn gây ra lỗi null-check, đồng thời vẫn giữ nguyên hành vi buộc tải xuống lại như dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
dart, flutter
Lĩnh vực
mobile-dev
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.