apache/dolphinscheduler · error · ServiceException
task instance is null or host is null
Error message
task instance is null or host is null
What it means
getLogBytes looks up the task instance by id and requires both the instance to exist and its host to be non-blank, because log bytes are fetched from the worker host. If the instance is missing or its host is empty, a ServiceException with the literal message 'task instance is null or host is null' is thrown instead of a typed status.
Source
Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/LoggerServiceImpl.java:113
Result<ResponseTaskLog> result = new Result<>(Status.SUCCESS.getCode(), Status.SUCCESS.getMsg());
String log = queryLog(taskInstance, skipLineNum, limit);
int lineNum = log.split("\\r\\n").length;
result.setData(new ResponseTaskLog(lineNum, log));
return result;
}
/**
* get log size
*
* @param loginUser login user
* @param taskInstId task instance id
* @return log byte array
*/
@Override
public byte[] getLogBytes(User loginUser, int taskInstId) {
TaskInstance taskInstance = taskInstanceDao.queryById(taskInstId);
if (taskInstance == null || StringUtils.isBlank(taskInstance.getHost())) {
throw new ServiceException("task instance is null or host is null");
}
Project project = projectDao.queryProjectByTaskInstanceId(taskInstId);
projectService.checkProjectAndAuthThrowException(loginUser, project, DOWNLOAD_LOG);
return getLogBytes(taskInstance);
}
/**
* query log
*
* @param loginUser login user
* @param projectCode project code
* @param taskInstId task instance id
* @param skipLineNum skip line number
* @param limit limit
* @return log string data
*/
@Override
@SuppressWarnings("unchecked")View on GitHub (pinned to 02eac45a1b)
Solutions
- Confirm taskInstId exists: query t_ds_task_instance for that id before downloading.
- Wait until the task has been dispatched and has a non-empty host; retry after the task starts running.
- Download logs from a completed, assigned task instance instead.
- If hosts are legitimately blank due to DB corruption, re-run the task to regenerate host info.
Example fix
// before: blind download
service.getLogBytes(loginUser, 999999);
// after: guard first
TaskInstance ti = taskInstanceDao.queryById(999999);
if (ti == null || StringUtils.isBlank(ti.getHost())) {
throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND);
}
service.getLogBytes(loginUser, 999999); Defensive patterns
Strategy: validation
Validate before calling
TaskInstance ti = taskInstanceDao.queryById(taskInstId);
if (ti == null || StringUtils.isBlank(ti.getHost())) {
throw new ServiceException(Status.TASK_INSTANCE_NOT_FOUND);
} Type guard
boolean isDownloadable(TaskInstance ti) { return ti != null && StringUtils.isNotBlank(ti.getHost()); } Try / catch
try {
byte[] log = loggerService.getLogBytes(loginUser, taskInstId);
} catch (ServiceException e) {
if (e.getMessage() != null && e.getMessage().contains("task instance is null")) {
// inform user the task has not run on any worker yet / does not exist
} else { throw e; }
} Prevention
- Only expose log download links for task instances in a completed/running state with a host.
- Poll the task status endpoint until host is populated before fetching logs.
- Purge old instances from UI history to avoid stale ids.
- Prefer queryLog-style endpoints returning typed statuses over the string-message variant.
When it happens
Trigger: Calling GET /log/download-log (or getLogBytes) with a taskInstId that does not exist, or whose task instance has an empty host (task not yet dispatched to a worker, or host data lost).
Common situations: Downloading logs for a task that failed before being assigned to a worker; requesting logs of a task instance deleted from the DB; stale UI link pointing at a purged instance id.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- TASK_INSTANCE_NOT_FOUND
- 10103
- The task instance is not under the project: {projectCode}
- The workflow instance is not finished: {workflowInstanceStat
- 10165
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/c95c6ab0f27a6dda.
Report an issue: GitHub.