Baseflow / Baseflow/flutter_cache_manager

Race condition when downloading the same URL with ignoreMemCache=true

Aperta
#338 1 commento 2 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Dart
Stelle
809
Fork
510
Merge medio
6m
PR unite (30g)
1

Descrizione

## 🐛 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.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start in flutter_cache_manager/lib/src/web/web_helper.dart, especially the _memCache assignment around lines 44-46 and cleanup around lines 73-76. Reproduce concurrent downloads of the same URL with ignoreMemCache=true and trace how the Subject is overwritten and removed. Done means the race no longer causes the null-check error while preserving the intended force-redownload behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
dart, flutter
Ambito
mobile-dev
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.