Exceptions other than IOExceptions, that occurred in the CacheWriter, block CachedContent forever
- Dominant language
- Java
- Stars
- 21.9k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello and thanks for the great library :)
I've faced an issue when using `ProgressiveDownloader` and `HlsDownloader` from ExoPlayer 2.16.1.
If they failed to perform downloading due to not `IOException`, `CacheWriter` in them never calls `dataSource.close()` (sources: [1](https://github.com/google/ExoPlayer/blob/release-v2/library/datasource/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheWriter.java#L160), [2](https://github.com/google/ExoPlayer/blob/release-v2/library/datasource/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheWriter.java#L173), [3](https://github.com/google/ExoPlayer/blob/release-v2/library/datasource/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheWriter.java#L196)) and because of that `CacheDataSource` remains opened and never calls `Cache.releaseHoleSpan()` -> `CachedContent.unlockRange()`, so `CachedContent` becomes blocked until the app restart.
Also I can't close data source manually, because I don't have an access to it in the `XxxDownloader`.
Example:
```
java.lang.IllegalStateException: Can't resolve source!
at myapppackage.UrlResolver.resolveDataSpec(UrlResolver.java:46)
at com.google.android.exoplayer2.upstream.ResolvingDataSource.open(ResolvingDataSource.java:106)
at com.google.android.exoplayer2.upstream.TeeDataSource.open(TeeDataSource.java:52)
at com.google.android.exoplayer2.upstream.cache.CacheDataSource.openNextSource(CacheDataSource.java:776)
at com.google.android.exoplayer2.upstream.cache.CacheDataSource.open(CacheDataSource.java:589)
at com.google.android.exoplayer2.upstream.cache.CacheWriter.readBlockToCache(CacheWriter.java:172)
at com.google.android.exoplayer2.upstream.cache.CacheWriter.cache(CacheWriter.java:134)
at com.google.android.exoplayer2.offline.ProgressiveDownloader$1.doWork(ProgressiveDownloader.java:95)
at com.google.android.exoplayer2.offline.ProgressiveDownloader$1.doWork(ProgressiveDownloader.java:92)
at com.google.android.exoplayer2.util.RunnableFutureTask.run(RunnableFutureTask.java:125)
at com.google.android.exoplayer2.offline.DefaultDownloaderFactory$$ExternalSyntheticLambda0.execute(Unknown Source:0)
at com.google.android.exoplayer2.offline.ProgressiveDownloader.download(ProgressiveDownloader.java:114)
```
If after that I'll try to open same dataSpec through the Cache, it will be blocked [here](https://github.com/google/ExoPlayer/blob/release-v2/library/datasource/src/main/java/com/google/android/exoplayer2/upstream/cache/SimpleCache.java#L374).
I think that CacheWriter must close datasources when any error occur, not only IOException.
Contributor guide
Assessment
This issue has not been assessed yet.