apache/flink · error · RuntimeException
An error occurred while copying the file.
Error message
An error occurred while copying the file.
What it means
Thrown by DistributedCache when fetching a registered cached file fails during the background copy from the distributed filesystem to local storage. The RuntimeException wraps the cause of an ExecutionException from a Future.get() call, meaning the asynchronous file-copy task threw an exception. Common root causes include network connectivity issues to HDFS/S3, permission denials, the file not existing at the registered path, or disk-full conditions on the local TaskManager.
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/cache/DistributedCache.java:162
if (name == null) {
throw new NullPointerException("name must not be null");
}
Future<Path> future = cacheCopyTasks.get(name);
if (future == null) {
throw new IllegalArgumentException(
"File with name '"
+ name
+ "' is not available."
+ " Did you forget to register the file?");
}
try {
final Path path = future.get();
URI tmp = path.makeQualified(path.getFileSystem()).toUri();
return new File(tmp);
} catch (ExecutionException e) {
throw new RuntimeException("An error occurred while copying the file.", e.getCause());
} catch (Exception e) {
throw new RuntimeException(
"Error while getting the file registered under '"
+ name
+ "' from the distributed cache",
e);
}
}
// ------------------------------------------------------------------------
// Utilities to read/write cache files from/to the configuration
// ------------------------------------------------------------------------
public static void writeFileInfoToConfig(
String name, DistributedCacheEntry e, Configuration conf) {
int num = conf.get(getIntConfigOption(CACHE_FILE_NUM), 0) + 1;
conf.set(getIntConfigOption(CACHE_FILE_NUM), num);
conf.setString(CACHE_FILE_NAME + num, name);View on GitHub (pinned to 2f3c205e92)
Solutions
- Check the getCause() of this RuntimeException to see the original failure (e.g. FileNotFoundException, AccessControlException, IOException) and address that specific issue.
- Verify the file path registered with registerCachedFile() actually exists and is readable by the TaskManager's service account.
- Ensure the TaskManager has sufficient free disk space and write permission on its configured temp directory (taskmanager.tmp.dirs / java.io.tmpdir).
- If using HDFS/S3, confirm connectivity and credentials from the TaskManager node (not just the client).
Example fix
// before
File cached = getRuntimeContext().getDistributedCache().getFile("model");
// after — inspect the root cause before retrying
try {
File cached = getRuntimeContext().getDistributedCache().getFile("model");
} catch (RuntimeException e) {
Throwable root = e.getCause() != null ? e.getCause() : e;
log.error("Distributed cache copy failed for 'model': {}", root.getMessage());
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Before calling getFile, verify the file is registered DistributedCache cache = getRuntimeContext().getDistributedCache(); // No public API to check registration; wrap in try-catch instead
Try / catch
try {
File cachedFile = getRuntimeContext().getDistributedCache().getFile("myFile");
} catch (RuntimeException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
log.error("Failed to fetch distributed cache file: {}", cause.getMessage(), cause);
throw e;
} Prevention
- Verify cached file paths exist and are accessible from TaskManager nodes before deploying.
- Use small files (< 100MB) for distributed cache to minimize copy failure window.
- Monitor TaskManager disk space to ensure temp directories have capacity.
- Test file accessibility from a TaskManager node using the same service account.
When it happens
Trigger: A user function calls RuntimeContext.getDistributedCache().getFile(name) for a file registered via DistributedCache.registerFileWithClasspathResolve() or ExecutionEnvironment.registerCachedFile(). The underlying future that copies the remote file to local temp storage fails, and ExecutionException is caught and re-thrown as this RuntimeException.
Common situations: The cached file path is wrong or was deleted after registration. The TaskManager lacks read permissions on HDFS/S3. Network partition between the TaskManager and the NameNode/object store. Local disk on the TaskManager is full or the temp directory is unwritable.
Related errors
- An I/O error occurred while creating temporary file to extra
- Failed to create parent(s) for given base dir: %s
- Failed to get the FileSystem of artifact {artifactFilePath}.
- Compaction file not exist: {path}
- Error while getting the file registered under '${name}' from
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/b421b65aee5a5616.
Report an issue: GitHub.