Baseflow / Baseflow/flutter_cache_manager
Race condition when downloading the same URL with ignoreMemCache=true
- 主要语言
- Dart
- 星标
- 809
- 派生
- 510
- 平均合并
- 6 分钟
- 30 天内合并 PR
- 1
描述
## 🐛 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.
贡献指南
调研方向
从 flutter_cache_manager/lib/src/web/web_helper.dart 开始,重点查看第 44-46 行附近的 _memCache 赋值,以及第 73-76 行附近的清理过程。使用 ignoreMemCache=true 重现对同一 URL 的并发下载,并跟踪 Subject 如何被覆盖和移除。完成的标准是该竞态不再导致 null-check 错误,同时保留预期的强制重新下载行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- dart, flutter
- 领域
- mobile-dev
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100