Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle CacheException? #8253

Closed
vhow opened this issue Nov 19, 2020 · 5 comments
Closed

How to handle CacheException? #8253

vhow opened this issue Nov 19, 2020 · 5 comments
Assignees
Labels

Comments

@vhow
Copy link

vhow commented Nov 19, 2020

I’m using v2.11.7, and it throws CacheException sometimes.

E/ExoPlayerImplInternal: Source error
E/ExoPlayerImplInternal: com.google.android.exoplayer2.upstream.cache.Cache$CacheException: Failed to create cache directory: /data/user/0/com.x.x/cache/
E/ExoPlayerImplInternal: at com.google.android.exoplayer2.upstream.cache.p.d(SimpleCache.java:522)
E/ExoPlayerImplInternal: at com.google.android.exoplayer2.upstream.cache.p.a(SimpleCache.java:50)
E/ExoPlayerImplInternal: at com.google.android.exoplayer2.upstream.cache.p$1.run(SimpleCache.java:268)
...
E/DownloadManager: Task failed: progressive:xxx, false
E/DownloadManager: com.google.android.exoplayer2.upstream.cache.Cache$CacheException: Failed to create cache directory: /data/user/0/com.xxx/cache/
E/DownloadManager: at com.google.android.exoplayer2.upstream.cache.p.d(SimpleCache.java:522)
E/DownloadManager: at com.google.android.exoplayer2.upstream.cache.p.a(SimpleCache.java:50)
E/DownloadManager: at com.google.android.exoplayer2.upstream.cache.p$1.run(SimpleCache.java:268)

@marcbaechinger
Copy link
Contributor

marcbaechinger commented Nov 24, 2020

The exception is thrown on L522 which with 2.11.7 is when the cache is initialized and the directory for storing the cached data needs to be created because it does not exist. The path /data/user/0/com.x.x/cache/ you are using is the cache directory you get from context.getCacheDir(). That actually seems about right to me and I would expect that it exists when starting up and it does not need to be created. context.getExternalCacheDir() would be an option, but I don't think it should fail with the path you are using, because it should actually exist.

You are saying it throws the exception only sometimes. Does this happen when you deploy from the IDE with adb to a emulator or a test device? When it does not work does it fail repeatedly? In general, do you have some more information about in what situation it fails?

@google-oss-bot
Copy link
Collaborator

Hey @vhow. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Collaborator

Since there haven't been any recent updates here, I am going to close this issue.

@vhow if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

@AChep
Copy link
Contributor

AChep commented Jan 14, 2021

This actually does happen for me every time on the first installation. Looking through the code

  private static void createCacheDirectories(File cacheDir) throws CacheException {
    if (!cacheDir.mkdirs()) {
      String message = "Failed to create cache directory: " + cacheDir;
      Log.e(TAG, message);
      throw new CacheException(message);
    }
  }

I found out that when I run cacheDir.exists() in the block it returns true. We should probably change the condition check to be

  private static void createCacheDirectories(File cacheDir) throws CacheException {
    if (!cacheDir.mkdirs() && !cacheDir.exists()) {
      String message = "Failed to create cache directory: " + cacheDir;
      Log.e(TAG, message);
      throw new CacheException(message);
    }
  }

And according to https://commons.apache.org/proper/commons-io/javadocs/api-2.5/src-html/org/apache/commons/io/FileUtils.html#line.2455 this is widely used.

@ojw28
Copy link
Contributor

ojw28 commented Jan 14, 2021

Reopening just to keep track of @AChep 's proposed solution to this issue. It's somewhat unclear why it would help, but it doesn't look like it can do any harm, so if it does help then we should merge it!

@ojw28 ojw28 closed this as completed Jan 21, 2021
@google google locked and limited conversation to collaborators Mar 23, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants