{"record":{"id":"9bd484703ad3785b","repo":"apache/flink","slug":"job-was-submitted-in-detached-mode-results-of-job","errorCode":null,"errorMessage":"Job was submitted in detached mode. Results of job execution, such as accumulators, runtime, etc. are not available. ","messagePattern":"Job was submitted in detached mode\\. Results of job execution, such as accumulators, runtime, etc\\. are not available\\. ","errorType":"exception","errorClass":"InvalidProgramException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/core/execution/DetachedJobExecutionResult.java","lineNumber":51,"sourceCode":"public final class DetachedJobExecutionResult extends JobExecutionResult {\n\n    public static final String DETACHED_MESSAGE = \"Job was submitted in detached mode. \";\n\n    public static final String EAGER_FUNCTION_MESSAGE =\n            \"Please make sure your program doesn't call \"\n                    + \"an eager execution function [collect, print, printToErr, count]. \";\n\n    public static final String JOB_RESULT_MESSAGE =\n            \"Results of job execution, such as accumulators,\"\n                    + \" runtime, etc. are not available. \";\n\n    public DetachedJobExecutionResult(final JobID jobID) {\n        super(jobID, -1, null);\n    }\n\n    @Override\n    public long getNetRuntime() {\n        throw new InvalidProgramException(DETACHED_MESSAGE + JOB_RESULT_MESSAGE);\n    }\n\n    @Override\n    public <T> T getAccumulatorResult(String accumulatorName) {\n        throw new InvalidProgramException(\n                DETACHED_MESSAGE + JOB_RESULT_MESSAGE + EAGER_FUNCTION_MESSAGE);\n    }\n\n    @Override\n    public Map<String, Object> getAllAccumulatorResults() {\n        throw new InvalidProgramException(DETACHED_MESSAGE + JOB_RESULT_MESSAGE);\n    }\n\n    @Override\n    public JobID getJobID() {\n        return super.getJobID();\n    }\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/core/execution/DetachedJobExecutionResult.java#L33-L69","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nJobExecutionResult result = env.execute(\"job\");\nlong runtime = result.getNetRuntime(); // throws in detached mode\n\n// after\nConfiguration config = new Configuration();\nconfig.set(ExecutionOptions.ATTACHED, true);\nenv.execute(\"job\");","handlingStrategy":"validation","validationCode":"if (result instanceof DetachedJobExecutionResult || !result.isJobExecutionResult()) {\n    throw new IllegalStateException(\"Cannot read runtime in detached mode\");\n}","typeGuard":"static boolean canReadMetrics(org.apache.flink.api.common.JobExecutionResult r) {\n    return !(r instanceof org.apache.flink.core.execution.DetachedJobExecutionResult);\n}","tryCatchPattern":"try {\n    long rt = result.getNetRuntime();\n} catch (InvalidProgramException e) {\n    if (e.getMessage().contains(\"detached mode\")) { /* run attached or skip */ }\n}","preventionTips":["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."],"tags":["execution","detached-mode","runtime"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}