apache/dolphinscheduler · error · TaskException

Cannot create TaskInstance WorkingDirectory:

Error message

Cannot create TaskInstance WorkingDirectory: 

What it means

createTaskInstanceWorkingDirectory throws TaskException when the per-task working directory cannot be created with 775 permission. FileUtils.createDirectoryWithPermission failed for any reason (I/O, permission, path issues), aborting task execution on the worker.

Source

Thrown at dolphinscheduler-worker/src/main/java/org/apache/dolphinscheduler/server/worker/utils/TaskExecutionContextUtils.java:60

public class TaskExecutionContextUtils {

    public static void createTaskInstanceWorkingDirectory(TaskExecutionContext taskExecutionContext) throws TaskException {
        // local execute path
        String taskInstanceWorkingDirectory =
                FileUtils.getTaskInstanceWorkingDirectory(taskExecutionContext.getTaskInstanceId());
        try {
            if (new File(taskInstanceWorkingDirectory).exists()) {
                FileUtils.deleteFile(taskInstanceWorkingDirectory);
                log.warn("The TaskInstance WorkingDirectory: {} is exist, will recreate again",
                        taskInstanceWorkingDirectory);
            }

            FileUtils.createDirectoryWithPermission(Paths.get(taskInstanceWorkingDirectory), FileUtils.PERMISSION_775);

            taskExecutionContext.setExecutePath(taskInstanceWorkingDirectory);
            taskExecutionContext.setAppInfoPath(FileUtils.getAppInfoPath(taskInstanceWorkingDirectory));
        } catch (Throwable ex) {
            throw new TaskException(
                    "Cannot create TaskInstance WorkingDirectory: " + taskInstanceWorkingDirectory + " failed", ex);
        }
    }

    public static ResourceContext downloadResourcesIfNeeded(TaskChannel taskChannel,
                                                            StorageOperator storageOperator,
                                                            TaskExecutionContext taskExecutionContext) {
        AbstractParameters abstractParameters = taskChannel.parseParameters(taskExecutionContext.getTaskParams());

        List<ResourceInfo> resourceFilesList = abstractParameters.getResourceFilesList();
        if (CollectionUtils.isEmpty(resourceFilesList)) {
            log.debug("There is no resource file need to download");
            return new ResourceContext();
        }

        ResourceContext resourceContext = new ResourceContext();
        String taskWorkingDirectory = taskExecutionContext.getExecutePath();

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Check the chained cause for the underlying mkdir/Files.createDirectory failure reason.
  2. Verify the worker user can write to the task execute base directory (execute.path) and that the disk is not full.
  3. Remove stale/conflicting directories with the same task-instance path and retry the task.
  4. Ensure the OS tenant user and worker process user have adequate umask/permissions to create 775 directories.

Example fix

// before
// execute base dir owned by root, worker runs as 'ds'
drwxr-x------ root root /opt/dolphinscheduler/exec
// after
cd /opt/dolphinscheduler && chown -R ds:dolphinscheduler exec && chmod 775 exec
Defensive patterns

Strategy: validation

Validate before calling

// pre-check on worker before submitting/executing tasks
Path base = Paths.get(executeBaseDir);
if (!Files.isDirectory(base)) throw new IllegalStateException("missing " + base);
if (!Files.isWritable(base)) throw new IllegalStateException("not writable: " + base);
if (Files.getUsableSpace(base) < minFreeBytes) throw new IllegalStateException("low disk");

Try / catch

try { TaskExecutionContextUtils.createTaskInstanceWorkingDirectory(ctx); } catch (TaskException e) { log.error("workdir creation failed for {}", ctx.getExecutePath(), e.getCause()); }

Prevention

When it happens

Trigger: Worker executes a task; building Paths.get(taskInstanceWorkingDirectory) or FileUtils.createDirectoryWithPermission(..., PERMISSION_775) throws (parent dir missing/unwritable, filesystem full, invalid path characters).

Common situations: Worker process runs as a user without write access to the task execute base directory; disk full; NFS/permission problems; leftover conflicting directory; Linux permission/umask preventing 775 creation.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/4eb96f69a466df37. Report an issue: GitHub.