CarGuo/GSYVideoPlayer · error · ProxyCacheException

Error closing file %s

Error message

Error closing file %s

What it means

FileCache.complete closes the temp file and renameTo()s name.download to name. If rename fails (returns false), it throws ProxyCacheException('Error renaming file X to Y for completion!'). Rename fails across filesystems, when the target exists, or when the file is still open/locked by another handle - leaving the cache permanently in .download state for that url.

Source

Thrown at gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/file/FileCache.java:83

        try {
            if (isCompleted()) {
                throw new ProxyCacheException("Error append cache: cache file " + file + " is completed!");
            }
            dataFile.seek(available());
            dataFile.write(data, 0, length);
        } catch (IOException e) {
            String format = "Error writing %d bytes to %s from buffer with size %d";
            throw new ProxyCacheException(String.format(format, length, dataFile, data.length), e);
        }
    }

    @Override
    public synchronized void close() throws ProxyCacheException {
        try {
            dataFile.close();
            diskUsage.touch(file);
        } catch (IOException e) {
            throw new ProxyCacheException("Error closing file " + file, e);
        }
    }

    @Override
    public synchronized void complete() throws ProxyCacheException {
        if (isCompleted()) {
            return;
        }

        close();
        String fileName = file.getName().substring(0, file.getName().length() - TEMP_POSTFIX.length());
        File completedFile = new File(file.getParentFile(), fileName);
        boolean renamed = file.renameTo(completedFile);
        if (!renamed) {
            throw new ProxyCacheException("Error renaming file " + file + " to " + completedFile + " for completion!");
        }
        file = completedFile;
        try {

View on GitHub (pinned to e5d74d3aa9)

Solutions

  1. Ensure exactly one HttpProxyCacheServer per cache directory and process
  2. On this error, delete the stale .download (and conflicting final file) for that url and re-cache
  3. Run a one-time cleanup at app start: remove leftover *.download files older than the previous session
  4. Keep the cache dir on internal storage where rename semantics are reliable

Example fix

// before - let the exception kill the caching thread

// after - startup cleanup of half-completed entries
File[] stale = cacheDir.listFiles((d, n) -> n.endsWith(".download"));
if (stale != null) for (File f : stale) f.delete();
Defensive patterns

Strategy: fallback

Validate before calling

File completed = new File(cacheDir, md5(url));
File temp = new File(cacheDir, md5(url) + ".download");
if (completed.exists() && temp.exists()) {
    temp.delete(); // resolve rename collision before completion runs
}

Try / catch

catch (ProxyCacheException e) {
    if (String.valueOf(e.getMessage()).contains("Error renaming")) {
        new File(cacheDir, md5(url) + ".download").delete(); // purge, will re-cache next time
    } else throw e;
}

Prevention

When it happens

Trigger: A completed file with the target name already exists (previous run crashed after rename but before cleanup); the temp file is held open by another fd (second reader); directory permissions changed; vendor filesystems that fail rename of open files.

Common situations: App killed mid-completion leaving both .download and final file; two proxy instances over one cache dir; some OEM/FUSE filesystems (scoped-storage emulation) rejecting renames of open files; cache dir on sdcardfs with quirky rename semantics.

Related errors


AI-assisted analysis of CarGuo/GSYVideoPlayer@e5d74d3aa9 (2026-08-14). Data as JSON: /api/errors/172629ab8c9ae497. Report an issue: GitHub.