apache/flink · error · InvalidProgramException
Job was submitted in detached mode. Results of job execution
Error message
Job was submitted in detached mode. Results of job execution, such as accumulators, runtime, etc. are not available.
What it means
Thrown by DetachedJobExecutionResult.getNetRuntime() when a job was submitted in detached mode and the program then tries to read the net runtime. In detached mode the client does not wait for completion, so runtime metrics are never collected. The result object is a placeholder that fails any metric query.
Source
Thrown at flink-core/src/main/java/org/apache/flink/core/execution/DetachedJobExecutionResult.java:51
public final class DetachedJobExecutionResult extends JobExecutionResult {
public static final String DETACHED_MESSAGE = "Job was submitted in detached mode. ";
public static final String EAGER_FUNCTION_MESSAGE =
"Please make sure your program doesn't call "
+ "an eager execution function [collect, print, printToErr, count]. ";
public static final String JOB_RESULT_MESSAGE =
"Results of job execution, such as accumulators,"
+ " runtime, etc. are not available. ";
public DetachedJobExecutionResult(final JobID jobID) {
super(jobID, -1, null);
}
@Override
public long getNetRuntime() {
throw new InvalidProgramException(DETACHED_MESSAGE + JOB_RESULT_MESSAGE);
}
@Override
public <T> T getAccumulatorResult(String accumulatorName) {
throw new InvalidProgramException(
DETACHED_MESSAGE + JOB_RESULT_MESSAGE + EAGER_FUNCTION_MESSAGE);
}
@Override
public Map<String, Object> getAllAccumulatorResults() {
throw new InvalidProgramException(DETACHED_MESSAGE + JOB_RESULT_MESSAGE);
}
@Override
public JobID getJobID() {
return super.getJobID();
}
View on GitHub (pinned to 2f3c205e92)
Solutions
- Run the job in attached mode (execution.attached=true) if you need runtime results.
- Remove getNetRuntime() calls from code paths that may run detached.
- Check isJobExecutionResult() or execution mode before accessing metrics.
Example fix
// before
JobExecutionResult result = env.execute("job");
long runtime = result.getNetRuntime(); // throws in detached mode
// after
Configuration config = new Configuration();
config.set(ExecutionOptions.ATTACHED, true);
env.execute("job"); Defensive patterns
Strategy: validation
Validate before calling
if (result instanceof DetachedJobExecutionResult || !result.isJobExecutionResult()) {
throw new IllegalStateException("Cannot read runtime in detached mode");
} Type guard
static boolean canReadMetrics(org.apache.flink.api.common.JobExecutionResult r) {
return !(r instanceof org.apache.flink.core.execution.DetachedJobExecutionResult);
} Try / catch
try {
long rt = result.getNetRuntime();
} catch (InvalidProgramException e) {
if (e.getMessage().contains("detached mode")) { /* run attached or skip */ }
} Prevention
- Run in attached mode if runtime metrics are required.
- Guard metric access with a detached-mode check.
- Avoid calling getNetRuntime on results from detached submissions.
When it happens
Trigger: Calling executionResult.getNetRuntime() after submitting a job with execution.attached=false (detached). This happens when programmatic code assumes a blocking result but the submission was non-blocking.
Common situations: Using Environment.execute() in detached mode and then reading runtime. Libraries that call getNetRuntime unconditionally. Switching a job from attached to detached without updating result-consuming code.
Related errors
- Job was submitted in detached mode. Results of job execution
- SplitFetcher thread %d received unexpected exception while p
- One or more fetchers have encountered exception
- A user-provided generator function threw an exception on thi
- A user-provided generator function threw an exception on thi
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/9bd484703ad3785b.
Report an issue: GitHub.